public async Task <IActionResult> UpdateAsync(int personId, int id, [FromBody] Address address) { if (address == null) { return(BadRequest()); } if (await _personRepository.GetAsync(personId) == null) { return(NotFound()); } var oldAddress = await _addressRepository.GetByForeignKeyAsync(personId, nameof(Address.PersonId), id); if (oldAddress == null) { return(NotFound()); } address.Id = id; address.PersonId = personId; if (!await _addressRepository.UpdateAsync(address)) { return(StatusCode(StatusCodes.Status500InternalServerError, "Unable to update address")); } _log.LogUpated(HttpContext.Request.Method, HttpContext.Request.Path, oldAddress, address); return(NoContent()); }
public async Task <IActionResult> UpdateUserAndPersonAsync(int id, [FromBody] Person person) { if (person == null) { return(BadRequest()); } var oldPerson = await _personRepository.GetFilterByInheritedAsync(typeof(User), id); var oldUser = await _userRepository.GetAsync(id); if (oldPerson == null || oldUser == null) { return(NotFound()); } person.Id = id; if (!await _personRepository.UpdateAsync(person)) { return(StatusCode(StatusCodes.Status500InternalServerError, "Unable to update users personal details")); } //comment: // User currently does not contain any field -> No need to update. // If update of User is needed, replace the Person object in '[FromBody] Person' with a DTO with both that implements IPerson and IUser and use Automapper to create Person and User objects. // Then find differences between old and new object on both person and object (using _changeLog.Changes(oldObj, updatedObj) and save to database _log.LogUpated(HttpContext.Request.Method, HttpContext.Request.Path, oldPerson, person); return(NoContent()); }
public async Task <IActionResult> UpdateAsync(int personId, int id, [FromBody] Email email) { if (email == null) { return(BadRequest()); } if (await _personRepository.GetAsync(personId) == null) { return(NotFound()); } var oldEmail = await _emailRepository.GetByForeignKeyAsync(personId, nameof(Email.PersonId), id); if (oldEmail == null) { return(NotFound()); } email.Id = id; email.PersonId = personId; if (!await _emailRepository.UpdateAsync(email)) { return(StatusCode(StatusCodes.Status500InternalServerError, "Unable to update email")); } _log.LogUpated(HttpContext.Request.Method, HttpContext.Request.Path, oldEmail, email); return(NoContent()); }
public async Task <IActionResult> UpdatePersonAsync(int id, [FromBody] Person person) { if (person == null) { return(BadRequest()); } var oldPerson = await _personRepository.GetAsync(id); if (oldPerson == null) { return(NotFound()); } if (!await _personRepository.UpdateAsync(person)) { return(StatusCode(StatusCodes.Status500InternalServerError, "Unable to update person")); } _log.LogUpated(HttpContext.Request.Method, HttpContext.Request.Path, oldPerson, person); return(NoContent()); }