public async Task <IActionResult> DeleteUserAndPersonAsync(int id) { var person = await _personRepository.GetAsync(id); var user = await _userRepository.GetAsync(id); if (user == null || person == null) { return(NotFound()); } if (!await _userRepository.DeleteAsync(user)) { return(StatusCode(StatusCodes.Status500InternalServerError, "Unable to delete user")); } if (!await _personRepository.DeleteAsync(person)) { return(StatusCode(StatusCodes.Status500InternalServerError, "Unable to delete person")); } _log.LogDeleted(HttpContext.Request.Method, HttpContext.Request.Path, multipleObjectsToJson(user, person).ToString()); return(NoContent()); }
public async Task <IActionResult> DeleteAsync(int id) { var person = await _personRepository.GetAsync(id); if (person == null) { return(NotFound()); } var user = await _userRepository.GetAsync(id); if (user != null) { await _userRepository.DeleteAsync(user); _log.LogDeleted(HttpContext.Request.Method, HttpContext.Request.Path, "user: "******"email: " + JsonConvert.SerializeObject(email).ToString()); } var addresses = await _addressRepository.GetFilterByForeignKey(id, nameof(Address.PersonId)); foreach (var address in addresses) { await _addressRepository.DeleteAsync(address); _log.LogDeleted(HttpContext.Request.Method, HttpContext.Request.Path, "address: " + JsonConvert.SerializeObject(address).ToString()); } if (!await _personRepository.DeleteAsync(person)) { return(StatusCode(StatusCodes.Status500InternalServerError, "Unable to delete person")); } _log.LogDeleted(HttpContext.Request.Method, HttpContext.Request.Path, JsonConvert.SerializeObject(person).ToString()); return(NoContent()); }
public async Task <IActionResult> DeleteAsync(int personId, int id) { if (await _personRepository.GetAsync(personId) == null) { return(NotFound()); } var address = await _addressRepository.GetByForeignKeyAsync(personId, nameof(Address.PersonId), id); if (address == null) { return(NotFound()); } if (!await _addressRepository.DeleteAsync(address)) { return(StatusCode(StatusCodes.Status500InternalServerError, "Unable to delete address")); } _log.LogDeleted(HttpContext.Request.Method, HttpContext.Request.Path, JsonConvert.SerializeObject(address).ToString()); return(NoContent()); }