public IActionResult Post(int publisherId, [FromBody] BookCreateDTO book) { if (book == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var publisherExists = _rep.PublisherExists(publisherId); if (!publisherExists) { return(NotFound()); } var bookToAdd = new BookDTO { PublisherId = publisherId, Title = book.Title }; _rep.AddBook(bookToAdd); _rep.Save(); return(CreatedAtRoute("GetBook", new { publisherId = publisherId, id = bookToAdd.Id }, bookToAdd)); }// end of POST method
public IActionResult Put(int id, [FromBody] PublisherUpdateDTO publisher) { if (publisher == null) { return(BadRequest()); } if (publisher.Established < 1534 || publisher.Established > DateTime.Now.Year) { ModelState.AddModelError("Established", "Первое издательское агенство было основано в 1534 г."); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var publisherExists = _rep.PublisherExists(id); if (!publisherExists) { return(NotFound()); } _rep.UpdatePublisher(id, publisher); _rep.Save(); return(NoContent()); }
public IActionResult Put(int id, [FromBody] PublisherUpdateDTO publisher) { if (publisher == null) { return(BadRequest()); } if (publisher.Established < 1534) { ModelState.AddModelError("Established", "The first publishing house was founded in 1534."); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var publisherExists = _rep.PublisherExists(id); if (!publisherExists) { return(NotFound()); } _rep.UpdatePublisher(id, publisher); _rep.Save(); return(NoContent()); }