public async Task <ActionResult> UpdateEmployeeAsync([FromBody] UpdateEmployeeModel updateEmployeeModel) { var employee = _employeeService.Get(updateEmployeeModel.EmployeeId); if (employee == null) { return(NotFound()); } if (!(await _authorizationService.AuthorizeAsync(User, employee, _updateAuthorizationRequirement)).Succeeded) { return(Forbid()); } try { _employeeService.UpdateEmployee(employee, updateEmployeeModel); } catch (ArgumentException) { return(BadRequest()); } var updatedEmployee = _mapper.Map <Employee, EmployeeModel>(employee); return(Ok(updatedEmployee)); }
public Employee UpdateEmployee(Employee employee, UpdateEmployeeModel updateModel) { employee.Name = updateModel.Name; employee.Age = updateModel.Age; _employeeRepository.Update(employee); return(employee); }
public ActionResult UpdateEmployee([FromBody] UpdateEmployeeModel updateEmployeeModel) { var employee = _employeeService.Get(updateEmployeeModel.EmployeeId); if (employee == null) { return(NotFound()); } try { _employeeService.UpdateEmployee(employee, updateEmployeeModel); } catch (InvalidOperationException) { return(BadRequest()); } var updatedEmployee = _mapper.Map <Employee, EmployeeModel>(employee); return(Ok(updatedEmployee)); }