public IActionResult Put(Guid authorId, Guid id, [FromBody] BookPutModel model) { model.AuthorId = authorId; model.Id = id; var book = _rpeo.UpdateBookForAuthor(model.GetEntity()); if (book == null) { return(NotFound()); } if (!_rpeo.Save()) { throw new Exception("Failed to update book"); } return(NoContent()); }
public async Task <ActionResult <BooksResponsePostModel> > Put([FromRoute] string id, [FromBody] BookPutModel model) { var response = new BooksResponsePostModel(); if (!string.IsNullOrEmpty(id) && _context.Books.Any(x => !x.Excluded && x.Id.ToString() == id)) { var book = _context.Books.SingleOrDefault(x => x.Id.ToString() == id); _context.Books.Update(model.UpdateByBook(book)); await _context.SaveChangesAsync(); response.Success = true; response.Result = _context.Books.FirstOrDefault(x => x.Id.ToString() == id); return(Ok(response)); } if (!response.Success) { response.Errors = new List <Error> { new Error { code = "02", message = "Não foi possivel Cadastra o Livro" } }; return(await Task.FromResult(BadRequest(response))); } response.Errors = new List <Error> { new Error { code = "01", message = "Dados Enviados são inválidos" } }; return(await Task.FromResult(BadRequest(response))); }