/**
  * This function takes care of the post method in edit event category page.
  *
  * @param string        POST Data
  *
  * @return if db error -> event category page with error message  | no errors -> event categories page with success message
  */
 public function EditEventCategoriesPost()
 {
     $input = Request::all();
     $iTasks = array();
     //if delete button is clicked, delete data from db
     if (isset($_POST['deltype'])) {
         $deliName = $input['evnamedel'];
         Event_Types::where('EventName', $deliName)->delete();
         Event_Services::where('EventName', $deliName)->delete();
         return redirect('dashboard/events/categories')->with('message', 'Record Deleted Successfully');
     } else {
         //get event name to variable
         $iName = $input['evname'];
         try {
             //delete exsisting event service data
             Event_Services::where('EventName', $iName)->delete();
             foreach ($input['eservices'] as $x) {
                 //insert new event service data
                 $iTasks[] = $x;
                 Event_Services::insert([['EventName' => $iName, 'Service' => $x]]);
             }
             //check if image upload has no errors
             if ($_FILES["img"]["error"] == 0) {
                 $iIcon = $input['img'];
                 $fileext = Request::file('img')->getClientOriginalExtension();
                 //if image is not png format. return with error message.
                 if ($fileext != 'png') {
                     return redirect('events/categories')->with('message', 'Record Update Failed');
                 }
                 //modify image name
                 $filename = Request::file('img')->getClientOriginalName();
                 $iName = $input['evname'];
                 $filefull = $iName . '.' . $fileext;
                 $filefull = str_replace(' ', '_', $filefull);
                 //upload the image to the path
                 Request::file('img')->move(base_path() . '/public/images/event-icons', $filefull);
                 Event_Types::where('EventName', $iName)->update(['Icon' => $filefull]);
             }
             return redirect('dashboard/events/categories/')->with('message', 'Record Updated Successfully');
         } catch (\Illuminate\Database\QueryException $e) {
             return redirect('dashboard/events/categories/')->with('message', 'Record Update Failed ' . $e->getCode());
         }
     }
 }