private void CheckForAdditionalModelValidationsForBook(BookForManipulationDto book) { //Ttitle and the description cannot be the same if (book.Title == book.Description) { ModelState.AddModelError("Title/Description", "The provided title and descripton cannot be the same."); } TryValidateModel(book); }
public IActionResult CreateBookForAuthor(int publisherId, BookForManipulationDto book) { if (!_repo.PublisherExists(publisherId)) { return(NotFound()); } var bookEntity = _mapper.Map <Book>(book); _repo.AddBook(publisherId, bookEntity); _repo.Save(); var bookForReturn = _mapper.Map <BookForReturnDto>(bookEntity); return(CreatedAtRoute("GetBookForAuthor", new { publisherId, id = bookForReturn.Id }, bookForReturn)); }
public IActionResult UpdateBook(int publisherId, int id, [FromBody] BookForManipulationDto book) { if (!_repo.PublisherExists(publisherId)) { return(NotFound()); } var bookFromRepo = _repo.GetBook(publisherId, id); if (bookFromRepo == null) { return(NotFound()); } _mapper.Map(book, bookFromRepo); _repo.UpdateBook(bookFromRepo); _repo.Save(); return(NoContent()); }