public async Task <Result> UpdateEmployee(long id, PutEmployeeDTO dto) { var employee = await this.dbContext.Employees .Where(e => e.Id == id) .Include(e => e.Contacts).SingleOrDefaultAsync(); if (employee == null) { return(Result.Failure($"Employee with id {id} not found")); } employee.Name = dto.Name; employee.Surname = dto.Surname; employee.Patronymic = dto.Patronymic; employee.BirthDate = dto.BirthDate; employee.Organization = dto.Organization; employee.Position = dto.Position; var contacts = this.GetContactsFromDTO(dto.Contacts); if (contacts.IsFailure) { return(Result.Failure($"Can't update contacts due to errors: {contacts.Error}")); } employee.ClearContacts(); employee.AddContacts(contacts.Value); await this.dbContext.SaveChangesAsync(); return(Result.Success()); }
public async Task <IActionResult> UpdateEmployee(long id, [FromBody] PutEmployeeDTO dto) { var result = await this.employeesService.UpdateEmployee(id, dto); return(result.IsSuccess ? Ok() : Error(result.Error)); }