public IActionResult Update([FromBody] Author updatedAuthor) { if (!repository.Exists(updatedAuthor.Id)) { return(NotFound()); } if (!repository.Update(updatedAuthor)) { ModelState.AddModelError("", $"Something went wrong updating {updatedAuthor.FirstName}"); return(StatusCode(500, ModelState)); } return(View(repository.GetById(updatedAuthor.Id))); }
public IActionResult Update(int bookId, [FromBody] Book updatedBook) { if (updatedBook == null || bookId != updatedBook.Id) { return(BadRequest(ModelState)); } if (!repository.Exists(bookId)) { return(NotFound()); } if (!repository.Update(updatedBook)) { ModelState.AddModelError("", $"Something went wrong updating {updatedBook.Title}"); return(StatusCode(500, ModelState)); } return(NoContent()); }