/**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(\App\Http\Requests\ProjectRequest $request)
 {
     $project = new Project();
     $project->fill($request->all());
     $project->created_by = Auth::user()->id;
     if ($project->save()) {
         $hasError = false;
         foreach ($request->input('allowed') as $key => $value) {
             $row = \App\User::where('id', $value);
             if ($row) {
                 $projectuser = new ProjectsUser();
                 $projectuser->user_id = $value;
                 $projectuser->project_id = $project->id;
                 $save = $projectuser->save();
                 if (!$save) {
                     $hasError = true;
                 }
             } else {
                 return redirect('/auth/logout');
             }
         }
         if ($hasError) {
             return redirect("/project")->with('success', 'There where some problems on sharing people, please edit project and try again');
         } else {
             return redirect('/project')->with('success', 'Project created succssfully');
         }
     } else {
         return redirect('/project')->with('success', 'A problem occured, please try again later!');
     }
 }
 /**
  * @param Request $request
  * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
  */
 public function create(Request $request)
 {
     if ($request->has('create')) {
         $project = new Project();
         $project->name = $request->get('name');
         $project->description = $request->get('description');
         $project->save();
     }
     return view('project.create');
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     try {
         $this->validate($request, ['project_name' => 'required|unique:project|max:255|min:3', 'project_desc' => 'required|min:1|max:500']);
         $ispublic = $request->input('is_public') ? true : false;
         $projectobj = new Project();
         $projectobj->project_name = $request->input('project_name');
         $projectobj->project_desc = $request->input('project_desc');
         $projectobj->is_public = $ispublic;
         $projectobj->is_active = true;
         $projectobj->save();
         return Redirect::to('/back/project/edit/' . $projectobj->id);
     } catch (Exception $e) {
         return Redirect::to('/back/project/create')->withwith('message', 'Oops! Something went wrong. Please try again later');
     }
 }
 public function addProject()
 {
     if (Request::ajax()) {
         $rules = ['projectName' => 'required'];
         $validator = Validator::make(Input::all(), $rules);
         if ($validator->fails()) {
             return Response::json(['result' => 'failed', 'error' => $validator->getMessageBag()->toArray()]);
         } else {
             $peopleId = Input::get('peopleId');
             $project = new ProjectModel();
             $project->projectName = Input::get('projectName');
             $project->peopleId = $peopleId;
             $project->projectDesc = Input::get('projectDescription');
             $project->save();
             $projectID = $project->id;
             $countResultDiv = Input::get('countResultDiv');
             if ($countResultDiv == 1) {
                 $projecTypeCheck = Input::get('projectType0');
                 if ($projecTypeCheck != "") {
                     $i = 0;
                     $ProjectZoneModelResult = new ProjectZoneModel();
                     $ProjectZoneModelResult->projectId = $projectID;
                     $ProjectZoneModelResult->ZoneName = '';
                     $ProjectZoneModelResult->projectZoneTypeId = Input::get('projectType' . $i);
                     $ProjectZoneModelResult->areaWidth = Input::get('w' . $i);
                     $ProjectZoneModelResult->areaLength = Input::get('l' . $i);
                     $ProjectZoneModelResult->areaHeight = Input::get('h' . $i);
                     $ProjectZoneModelResult->areaSquareFoot = Input::get('sq' . $i);
                     $ProjectZoneModelResult->AreaUnitId = Input::get('unit' . $i);
                     $ProjectZoneModelResult->freshAirVelocity = Input::get('airVelocity' . $i);
                     $ProjectZoneModelResult->freshAirVelocityUnitId = Input::get('airVelocityUnit' . $i);
                     $ProjectZoneModelResult->exhastAirVelocity = Input::get('exhaustVelocity' . $i);
                     $ProjectZoneModelResult->exhastAirVelocityUnitId = Input::get('exhaustVelocityUnit' . $i);
                     $ProjectZoneModelResult->freshAir = Input::get('freshAir' . $i);
                     $ProjectZoneModelResult->ductWidth = Input::get('ductW' . $i);
                     $ProjectZoneModelResult->ductHeight = Input::get('ductH' . $i);
                     $ProjectZoneModelResult->ductAirVelocity = Input::get('ductAirVelocity' . $i);
                     $ProjectZoneModelResult->OutdoorTemp = Input::get('outDoorTemp' . $i);
                     $ProjectZoneModelResult->OutdoorTempUnitId = Input::get('outTempUnit' . $i);
                     $ProjectZoneModelResult->TargetTemp = Input::get('targetTemp' . $i);
                     $ProjectZoneModelResult->TargetTempUnitId = Input::get('targetTempUnit' . $i);
                     $ProjectZoneModelResult->custom = Input::get('custom' . $i);
                     $ProjectZoneModelResult->note = Input::get('notes' . $i);
                     $ProjectZoneModelResult->save();
                 }
             } else {
                 for ($i = 0; $i < $countResultDiv; $i++) {
                     $projectType = Input::get('projectType' . $i);
                     $rules = ['projectType' . $i => 'required'];
                     $validator = Validator::make(Input::all(), $rules);
                     if ($validator->fails()) {
                         return Response::json(['result' => 'failed', 'error' => $validator->getMessageBag()->toArray()]);
                     }
                 }
                 for ($i = 0; $i < $countResultDiv; $i++) {
                     $ProjectZoneModelResult = new ProjectZoneModel();
                     $ProjectZoneModelResult->projectId = $projectID;
                     $ProjectZoneModelResult->ZoneName = '';
                     $ProjectZoneModelResult->projectZoneTypeId = Input::get('projectType' . $i);
                     $ProjectZoneModelResult->areaWidth = Input::get('w' . $i);
                     $ProjectZoneModelResult->areaLength = Input::get('l' . $i);
                     $ProjectZoneModelResult->areaHeight = Input::get('h' . $i);
                     $ProjectZoneModelResult->areaSquareFoot = Input::get('sq' . $i);
                     $ProjectZoneModelResult->AreaUnitId = Input::get('unit' . $i);
                     $ProjectZoneModelResult->freshAirVelocity = Input::get('airVelocity' . $i);
                     $ProjectZoneModelResult->freshAirVelocityUnitId = Input::get('airVelocityUnit' . $i);
                     $ProjectZoneModelResult->exhastAirVelocity = Input::get('exhaustVelocity' . $i);
                     $ProjectZoneModelResult->exhastAirVelocityUnitId = Input::get('exhaustVelocityUnit' . $i);
                     $ProjectZoneModelResult->freshAir = Input::get('freshAir' . $i);
                     $ProjectZoneModelResult->ductWidth = Input::get('ductW' . $i);
                     $ProjectZoneModelResult->ductHeight = Input::get('ductH' . $i);
                     $ProjectZoneModelResult->ductAirVelocity = Input::get('ductAirVelocity' . $i);
                     $ProjectZoneModelResult->OutdoorTemp = Input::get('outDoorTemp' . $i);
                     $ProjectZoneModelResult->OutdoorTempUnitId = Input::get('outTempUnit' . $i);
                     $ProjectZoneModelResult->TargetTemp = Input::get('targetTemp' . $i);
                     $ProjectZoneModelResult->TargetTempUnitId = Input::get('targetTempUnit' . $i);
                     $ProjectZoneModelResult->custom = Input::get('custom' . $i);
                     $ProjectZoneModelResult->note = Input::get('notes' . $i);
                     $ProjectZoneModelResult->save();
                 }
             }
             $url = URL::route('user.project.add', $peopleId);
             return Response::json(['result' => 'success', 'url' => $url, 'message' => "Your project has been saved successfully."]);
         }
     }
 }