Esempio n. 1
0
 public function store()
 {
     try {
         //get the input for the new user
         $addModel = Input::json()->all();
         //make a new user and then set the properties
         $addUser = new ScansUser();
         $addUser->user_name = $addModel['user_name'];
         $addUser->total = $addModel['total'];
         $addUser->last_scanned = $addModel['last_scanned'];
         //save the new user and return it
         $addUser->save();
         return $addUser->toJSON();
     } catch (Exception $e) {
         return json_encode('{"error":{"text":' . $e->getMessage() . '}}');
     }
 }
 public function update($id)
 {
     //get the json from the request.
     $updateModel = Input::json()->all();
     //update the scan model based on the json data sent.
     $updateScan = Scans::find($id);
     $updateScan->mac_addr = $updateModel['mac_addr'];
     $updateScan->scan_date = $updateModel['scan_date'];
     $updateScan->room_number = $updateModel['room_number'];
     $updateScan->cpu_desc = $updateModel['cpu_desc'];
     $updateScan->troj_mal = $updateModel['troj_mal'];
     $updateScan->pups = $updateModel['pups'];
     $updateScan->notes = $updateModel['notes'];
     $updateScan->scanned_by = $updateModel['scanned_by'];
     //if the user doesn't exist, it makes a new user. Otherwise, it gets the user for this scan
     $scanUser = ScansUser::where('user_name', '=', $updateModel['user_name'])->first();
     if ($scanUser == null) {
         $scanUser = new ScansUser();
         $scanUser->user_name = $updateModel['user_name'];
         $scanUser->save();
     }
     //if the user for the update and the old user are different, then update each one
     if ($updateScan->uid != $scanUser->id) {
         $oldScanUser = $updateScan->getScansUserById();
         $updateScan->uid = $scanUser->id;
         $updateScan->save();
         $oldScanUser->updateTotal();
         $oldScanUser->updateMostRecentScan();
         $scanUser->updateTotal();
         $scanUser->updateMostRecentScan();
     } else {
         //if its still the same user, just update the one person
         $updateScan->save();
         $scanUser->updateTotal();
         $scanUser->updateMostRecentScan();
     }
     //send the response
     return $updateScan->toJson();
 }