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); }
public void Post(PostAuthorView author) { var authorModel = Mapper.Map <PostAuthorView, Author>(author); var authorBooksModel = new List <BookAuthor>(); var authorId = _authorRepository.Insert(authorModel); foreach (var book in author.Books) { authorBooksModel.Add(new BookAuthor() { AuthorId = authorId, BookId = book.Id }); } _bookInAuthorRepository.Insert(authorBooksModel); }