Beispiel #1
0
        public async void AddBook(BookInputModel book)
        {
            var bookEntity = new Book
            {
                Title          = book.Title,
                Isbn           = book.Isbn,
                PublishingYear = book.PublishingYear ?? default(int),
                Type           = book.Type,
                Price          = book.Price ?? default(double),
                PublisherId    = book.PublisherId ?? default(int)
            };

            var bookId = _bookRepo.AddBook(bookEntity);

            var details = new BookDetails
            {
                BookId      = bookId,
                Description = book.Description,
                Font        = book.Font,
                PageCount   = book.PageCount ?? default(int),
                Length      = book.Length ?? default(int)
            };

            _bookRepo.AddBookDetails(details);

            foreach (var id in book.Author)
            {
                var AuthorConnection = new BookAuthorConnection
                {
                    BookId   = bookId,
                    AuthorId = id
                };

                _bookRepo.AddBookAuthorConnection(AuthorConnection);
            }

            foreach (var id in book.Genre)
            {
                var GenreConnection = new BookGenreConnection
                {
                    BookId  = bookId,
                    GenreId = id
                };
                _bookRepo.AddBookGenreConnection(GenreConnection);
            }

            using (var memoryStream = new MemoryStream())
            {
                await book.CoverImage.CopyToAsync(memoryStream);

                var img = new CoverImage
                {
                    BookId = bookId,
                    Img    = memoryStream.ToArray()
                };
                _bookRepo.AddImage(img);
            }
        }