public IActionResult Delete(int authorId) { if (!repository.Exists(authorId)) { return(NotFound()); } Author authorToDelete = repository .GetById(authorId); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!repository.Delete(authorToDelete)) { ModelState .AddModelError("", $"Something went wrong deleting {authorToDelete.FirstName}"); return(StatusCode(500, ModelState)); } return(NoContent()); }
public IActionResult Delete(int bookId) { if (!repository.Exists(bookId)) { return(NotFound()); } Book bookToDelete = repository .GetById(bookId); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!repository.Delete(bookToDelete)) { ModelState .AddModelError("", $"Something went wrong deleting {bookToDelete.Title}"); return(StatusCode(500, ModelState)); } return(NoContent()); }