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 Post([FromBody] PublisherCreateDTO 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 publisherToAdd = new PublisherDTO { Established = publisher.Established, Name = publisher.Name }; _rep.AddPublisher(publisherToAdd); _rep.Save(); return(CreatedAtAction("GetPublisher", new { id = publisherToAdd.Id }, publisherToAdd)); }
public IActionResult Post([FromBody] PublisherCreateDTO 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 publisherToAdd = new PublisherDTO { Established = publisher.Established, Name = publisher.Name }; _rep.AddPublisher(publisherToAdd); _rep.Save(); return(CreatedAtRoute("GetPublisher", new { id = publisherToAdd.Id }, publisherToAdd)); }