public HttpResponseMessage Put([FromBody] EmployeeInfo value) { try { employeeService.UpdateEmployee(value); return(Request.CreateResponse(HttpStatusCode.OK, "Record updated successfully.")); } catch { return(Request.CreateResponse(HttpStatusCode.InternalServerError, "An error occured while updating record.")); } }
// PUT api/EmployeeInfoAPI/5 public HttpResponseMessage PutEmployeeInfo(int id, EmployeeInfo employeeinfo) { if (employeeinfo == null) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } // INTERVIEW_TODO: 3. Implement the UpdateEmployee method of the employee service // Details: // The previous developer didn't implement the UpdateEmployee function, // modify the existing UpdateEmployee method to find the employee, and update the record. // Question 1: How do we ensure that the employee exists, what should we do if they don't? - Return BadRequest // Question 2: What unit tests do we need to implement? - Implemented unit test for both controller and service class. if (ModelState.IsValid && id == employeeinfo.EmpNo) { var success = _service.UpdateEmployee(id, employeeinfo); return(success ? Request.CreateResponse(HttpStatusCode.OK) : Request.CreateResponse(HttpStatusCode.BadRequest)); } return(Request.CreateResponse(HttpStatusCode.BadRequest)); }
private void SaveEmployee(object obj) { employeeInfoService.UpdateEmployee(selectedEmployee); WeakReferenceMessenger.Default.Send(new UpdateEmployeeListMessage()); }