public async Task <ActionResult <EmployeeDocument> > Edit(int id, [FromBody] EmployeeDocument employee) { if (id != employee.Id) { return(BadRequest()); } var employeeDto = await _employeeService.GetByIdAsync(id); if (employeeDto == null) { return(NotFound($"Employee with id: '{id}' not found")); } var departmentDto = await DepartmentService.GetByIdAsync(employee.DepartmentId); if (departmentDto == null) { return(NotFound($"Department with id: '{employee.DepartmentId}' not found")); } await _employeeService.EditAsync(id, employee.ToEmployeeDto()); return(NoContent()); }
public async Task <ActionResult <EmployeeDocument> > Create([FromBody] EmployeeDocument employee) { var departmentDto = await DepartmentService.GetByIdAsync(employee.DepartmentId); if (departmentDto == null) { return(NotFound($"Department with id: '{employee.DepartmentId}' not found")); } var createEmployee = await _employeeService.CreateAsync(employee.ToEmployeeDto()); return(CreatedAtAction(nameof(GetById), new { id = createEmployee.Id }, createEmployee.ToEmployeeDocument())); }