<?php

namespace DummyNamespace;

use Illuminate\Http\Request;
use DummyRootNamespaceHttp\Controllers\Controller;
use App\Contracts\DummyContract;
use Exception;

class DummyClass extends Controller{
    
    protected $DummyServiceVar;

    public function __construct(DummyContract $DummyServiceVar) {
        $this->DummyServiceVar = $DummyServiceVar;
    }

    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(){
        return view('admin.DummyViewPath.index')->with(['DummyServiceVar'=>$this->DummyServiceVar->get()]);
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create(){
        return view('admin.DummyViewPath.create');
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request){
        $this->validate($request, []);
        
        try{
            $this->DummyServiceVar->create($request->all());
            return redirect()->route('admin.DummyViewPath.index')->withMessage(trans('crud.record_created'));
        } catch (Exception $ex) {
            return redirect()->back()->withErrors($ex->getMessage())->withInput();
        }
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id){
        return view('admin.DummyViewPath.show')->with(['DummySingularServiceVar'=>$this->DummyServiceVar->find($id)]);
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id){
        return view('admin.DummyViewPath.edit')->with(['DummySingularServiceVar'=>$this->DummyServiceVar->find($id)]);
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id){
        $this->validate($request, []);
        
        try{
            $this->DummyServiceVar->update($id, $request->all());
            return redirect()->route('admin.DummyViewPath.index')->withMessage(trans('crud.record_updated'));
        } catch (Exception $ex) {
            return redirect()->back()->withInput()->withErrors($ex->getMessage());
        }
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id){
        try{
            $this->DummyServiceVar->delete($id);
            return redirect()->route('admin.DummyViewPath.index')->withMessage(trans('crud.record_deleted'));
        } catch (Exception $ex) {
            return redirect()->route('admin.DummyViewPath.index')->withErrors($ex->getMessage());
        }
    }
}

