Esempio n. 1
0
        public void Post(PostBookView book)
        {
            var bookModel                  = Mapper.Map <PostBookView, Book>(book);
            var bookAuthorsModel           = new List <BookAuthor>();
            var bookPublicationHousesModel = new List <BookPublicationHouse>();

            var bookId = _bookRepository.Insert(bookModel);

            foreach (var author in book.Authors)
            {
                bookAuthorsModel.Add(new BookAuthor()
                {
                    BookId = bookId, AuthorId = author.Id
                });
            }
            foreach (var publicationHouse in book.PublicationHouses)
            {
                bookPublicationHousesModel.Add(new BookPublicationHouse()
                {
                    BookId = bookId, PublicationHouseId = publicationHouse.Id
                });
            }

            _bookInAuthorRepository.Insert(bookAuthorsModel);
            _bookInPublicationHouseRepository.Insert(bookPublicationHousesModel);
        }
Esempio n. 2
0
 public IActionResult Post([FromBody] PostBookView book)
 {
     if (ModelState.IsValid)
     {
         _bookService.Post(book);
         return(Ok(book));
     }
     return(BadRequest(ModelState));
 }