Exemple #1
0
 public IActionResult ModifyBookById(BookModifyInputModel model)
 {
     if (ModelState.IsValid)
     {
         _bookService.ModifyBook(model);
         return(Ok());
     }
     return(BadRequest());
 }
Exemple #2
0
        public BookModifyInputModel GetBookModify(int bookId)
        {
            var book       = GetBook(bookId);
            var details    = GetDetails(bookId);
            var coverImage = GetCoverImageAsync(bookId);

            var authorIds = (from bac in _db.BookAuthorConnections
                             where bac.BookId == bookId
                             join a in _db.Authors on bac.AuthorId equals a.Id
                             select a.Id).ToList();

            var genreIds = (from bgc in _db.BookGenreConnections
                            where bgc.BookId == bookId
                            join g in _db.Genres on bgc.GenreId equals g.Id
                            select g.Id).ToList();

            var publisherId = (from p in _db.Publishers
                               where p.Id == book.PublisherId
                               select p.Id).SingleOrDefault();

            var bookDetails = new BookModifyInputModel
            {
                BookId            = book.Id,
                Title             = book.Title,
                Isbn              = book.Isbn,
                Author            = authorIds,
                Publisher         = publisherId,
                Genre             = genreIds,
                Description       = details.Description,
                Price             = book.Price,
                Type              = book.Type,
                Font              = details.Font,
                PublishingYear    = book.PublishingYear,
                PageCount         = details.PageCount,
                Length            = details.Length,
                CurrentCoverImage = coverImage
            };

            return(bookDetails);
        }
Exemple #3
0
        public async void ModifyBook(BookModifyInputModel book)
        {
            var bookEntity = new Book
            {
                Id             = book.BookId,
                Title          = book.Title,
                Isbn           = book.Isbn,
                PublishingYear = book.PublishingYear ?? default(int),
                Type           = book.Type,
                Price          = book.Price ?? default(double),
                PublisherId    = book.Publisher ?? default(int)
            };

            _bookRepo.ModBook(bookEntity);

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

            _bookRepo.ModBookDetails(details);

            var genreConnections = _bookRepo.GetBookGenreConnections(book.BookId);

            foreach (var g in genreConnections)
            {
                _bookRepo.RemoveBookGenreConnection(g);
            }

            foreach (var g in book.Genre)
            {
                var genreConnection = new BookGenreConnection
                {
                    BookId  = book.BookId,
                    GenreId = g
                };
                _bookRepo.AddBookGenreConnection(genreConnection);
            }

            var authorConnections = _bookRepo.GetBookAuthorConnections(book.BookId);

            foreach (var a in authorConnections)
            {
                _bookRepo.RemoveBookAuthorConnection(a);
            }

            foreach (var a in book.Author)
            {
                var authorConnection = new BookAuthorConnection
                {
                    BookId   = book.BookId,
                    AuthorId = a
                };
                _bookRepo.AddBookAuthorConnection(authorConnection);
            }

            if (book.NewCoverImage != null)
            {
                using (var memoryStream = new MemoryStream())
                {
                    await book.NewCoverImage.CopyToAsync(memoryStream);

                    var img = new CoverImage
                    {
                        Id     = _bookRepo.GetCoverImageId(book.BookId),
                        BookId = book.BookId,
                        Img    = memoryStream.ToArray()
                    };
                    _bookRepo.ModImage(img);
                }
            }
        }