示例#1
0
        public bool Add(Book book)
        {
            var bookId = _bookRepository.Add(new BookDto()
            {
                Name        = book.Name,
                Description = book.Description,
                ReleaseDate = book.ReleaseDate,
                Image       = book.Image
            });

            var isBookAdded = _goodRepository.AddGood(new GoodDto()
            {
                BookId = bookId,
                Count  = book.Count,
                Price  = book.Price
            });

            _authorRepository.DeleteBookAuthorByBookId(bookId);
            _genreRepository.DeleteBookGenreByBookId(bookId);

            book.AuthorIds.ForEach(authorId =>
            {
                _authorRepository.AddBookAuthor(new BookAuthorDto()
                {
                    BookId   = bookId,
                    AuthorId = authorId
                });
            });

            book.GenreIds.ForEach(genreId =>
            {
                _genreRepository.AddBookGenre(new BookGenreDto()
                {
                    BookId  = bookId,
                    GenreId = genreId
                });
            });

            return(isBookAdded);
        }