public IActionResult UpdateQuote(int personId, int quoteId, [FromBody] QuoteForUpdateDto quote) { if (quote == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!_personRepository.PersonExist(personId)) { return(NotFound()); } var quoteEntity = _personRepository.GetQuoteForPerson(personId, quoteId); if (quoteEntity == null) { return(BadRequest()); } Mapper.Map(quote, quoteEntity); if (!_personRepository.Save()) { return(StatusCode(500, "Sorry, something wrong")); } return(NoContent()); }
public IActionResult UpdateQuote(int bookId, int id, [FromBody] QuoteForUpdateDto quote) { //Check book and quote exist if (!_bookInfoRepository.BookExists(bookId)) { return(NotFound()); } var quoteEntity = _bookInfoRepository.GetQuotationForBook(bookId, id); if (quoteEntity == null) { return(NotFound()); } // update... _mapper.Map(quote, quoteEntity); // call to update on repository _bookInfoRepository.UpdateQuoteForBook(bookId, quoteEntity); // changes tracked by DbContext _bookInfoRepository.Save(); return(NoContent()); }