<?php

namespace App\Http\Controllers\Hr;
use Illuminate\Http\Request;
use App\Http\Requests\DesignationRequest;
use Illuminate\Contracts\Encryption\DecryptException;
use App\Http\Controllers\Controller;
use App\Designation;


class DesignationController extends Controller
{
    public function index()
    {   
        $designation = new Designation;
        
        return view('hr.designation.manage_designation',
        	[

        		'designation_list'       => $designation->getDesignationList(),
        		
        	]
    );
       
    }

    public function storeDesignation(DesignationRequest $request)
    {
        $designation = new Designation;

        $curr_designation = $designation->storeDesignation($request->input());

        if(isset($curr_designation->id))
        {
            parent::setLogMessage('Designation "'.$curr_designation->title.'" has been created');

            parent::successMessage('Designation has been created.',parent::getLogMessage());
        }

        return redirect('designation');
    }


     public function updateDesignation(DesignationRequest $request)
    {

        try 
        {
            $id = decrypt($request->designation);

            $designation = new Designation;


            $curr_designation = $designation->updateDesignation($request->input(),$id);

            if(isset($curr_designation->id))
            {
                parent::setLogMessage('Designation "'.$curr_designation->title.'" has been updated');

                parent::successMessage('Designation has been updated.',parent::getLogMessage());
            }
        } 
        catch (DecryptException $e) 
        {
            
        }

        return redirect('designation');
    }
}
