コード例 #1
0
        public IActionResult DetailsAsync(int?id)
        {
            var allBooks = _bookService.GetAllBooks();

            if (id > allBooks.Count)
            {
                return(View("Error"));
            }
            double totalForAverage = 0;
            var    books           = _bookService.GetAllBooksDetails();


            var book = new BookDetailsViewModel();

            for (int i = 0; i < books.Count; i++)
            {
                if (books[i].BookId == id)
                {
                    book = books[i];
                }
                book.Reviews = _bookService.GetReviews(id);
            }
            for (int i = 0; i < book.Reviews.Count; i++)
            {
                totalForAverage += book.Reviews[i].Ratings;
            }
            book.AverageRating = totalForAverage / book.Reviews.Count;

            if (double.IsNaN(book.AverageRating))
            {
                book.AverageRating = 0.0;
            }
            return(View(book));
        }
コード例 #2
0
        public ActionResult Details(int?id, string returnUrl)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            Book book = db.Books.Include(b => b.Genre).FirstOrDefault(b => b.Id == id);

            if (book == null)
            {
                return(HttpNotFound());
            }

            var booksByGenre = db.Books.Include(b => b.Genre).Where(b => b.Genre.Name == book.Genre.Name).ToList();

            booksByGenre.Remove(book);

            var reviewsForBook = book.Reviews.OrderByDescending(item => item.ReviewDate).ToList();

            var model = new BookDetailsViewModel()
            {
                Book           = book,
                BooksByGenre   = booksByGenre,
                ReviewsForBook = reviewsForBook
            };

            ViewBag.ReturnUrl = returnUrl;
            return(View(model));
        }
コード例 #3
0
        public List <BookDetailsViewModel> GetAllBooks()
        {
            string query = "SELECT * FROM Books AS b INNER JOIN Department AS d ON b.DepartmentId=d.Id";

            Command = new SqlCommand(query, Connection);
            Connection.Open();
            Reader = Command.ExecuteReader();
            List <BookDetailsViewModel> BookList = new List <BookDetailsViewModel>();

            while (Reader.Read())
            {
                BookDetailsViewModel aBooks = new BookDetailsViewModel();
                aBooks.Id             = Convert.ToInt32(Reader["Id"]);
                aBooks.BookName       = Reader["BookName"].ToString();
                aBooks.BookId         = Reader["BookId"].ToString();
                aBooks.AuthorName     = Reader["AuthorName"].ToString();
                aBooks.DepartmentName = Reader["DepartmentName"].ToString();
                aBooks.Price          = Convert.ToInt32(Reader["Price"]);
                aBooks.Quantity       = Convert.ToInt32(Reader["Quantity"]);


                BookList.Add(aBooks);
            }
            Connection.Close();
            return(BookList);
        }
        public ActionResult Details(int id)
        {
            var book = _unitOfWork.BookRepository.Get(x => x.Id == id);

            if (book == null)
            {
                return(NotFound());
            }

            var viewModel = new BookDetailsViewModel()
            {
                BookId      = book.Id,
                Name        = book.Name,
                Description = book.Description,
                Author      = book.Author,
                CreatedAt   = book.CreatedAt,
                Draft       = book.Draft,
                PhotoPath   = book.PhotoPath,
                ReleaseYear = book.ReleaseYear,
                User        = book.User,
                Category    = book.Category
            };


            return(View(viewModel));
        }
コード例 #5
0
        public ActionResult Detail(string id)
        {
            var service = new BooksService(new BaseClientService.Initializer()
            {
            });

            var request = service.Volumes.Get(id);
            var result  = request.Execute();

            var industryIdentifier = result.VolumeInfo.IndustryIdentifiers.First(x => x.Type == "ISBN_13") ?? result.VolumeInfo.IndustryIdentifiers.First(x => x.Type == "ISBN_10");
            var imageLink          = result.VolumeInfo.ImageLinks.Thumbnail;

            var viewModel = new BookDetailsViewModel {
                Author      = result.VolumeInfo.Authors.Aggregate((i, j) => i + ", " + j),
                ISBN        = industryIdentifier.Identifier,
                Title       = result.VolumeInfo.Title,
                ImageLink   = imageLink,
                Id          = id,
                Description = result.VolumeInfo.Description
            };

            viewModel.Questions = new List <string> {
                "Which charater do you relate to the best, why?"
            };

            return(View(viewModel));
        }
コード例 #6
0
        public async Task <IActionResult> BookDetails(int bookId)
        {
            Book book = _dbContext.Books.Find(bookId);

            if (book == null)
            {
                return(NotFound());
            }

            List <Category> categories = _dbContext.Categories
                                         .Where(c => c.BookCategories.Any(bc => bc.BookId == bookId)).ToList();

            var ratingQuery = _dbContext.Reviews.Where(r =>
                                                       r.User.Id == _userManager.GetUserId(this.User) && r.Book.BookId == bookId);

            BookDetailsViewModel bookDetailsView = new BookDetailsViewModel
            {
                BookId            = bookId,
                Title             = book.Title,
                Author            = book.Author,
                Isbn              = book.Isbn,
                Description       = book.Description,
                ImageFileName     = book.ImageFile,
                Categories        = categories,
                UserRating        = ratingQuery.Any() ? ratingQuery.First().Rating : 0,
                BwaRating         = GetBwaRating(bookId),
                GoogleBooksRating = await GetGoogleBooksRating(book.Isbn)
            };

            return(View(bookDetailsView));
        }
コード例 #7
0
        public async Task <IActionResult> Details(string id)
        {
            var book = await context.Books
                       .Include(b => b.BookItems)
                       .SingleOrDefaultAsync(b => b.Id == id);

            if (book == null)
            {
                return(NotFound());
            }

            var model = new BookDetailsViewModel
            {
                Id        = book.Id,
                Author    = book.Author,
                Title     = book.Title,
                Isbn      = book.Isbn,
                BookItems = book.BookItems.Select(i => new BookItemListViewModel
                {
                    Id        = i.Id,
                    Barcode   = i.Barcode,
                    State     = i.State,
                    Condition = i.Condition.ToString()
                }).ToList()
            };

            return(Ok(model));
        }
コード例 #8
0
ファイル: BooksController.cs プロジェクト: BiserB/Educational
        public IActionResult Details(int id)
        {
            if (!DbContext.Books.Any(b => b.Id == id))
            {
                ViewData["Message"] = "Error! There is no such book!";

                return(View());
            }

            var book = DbContext.Books.Find(id);

            string authorName = DbContext.Authors.First(a => a.Id == book.AuthorId).Name;

            string categoryName = DbContext.Categories.First(c => c.Id == book.CategoryId).Name;

            bool available = book.Loans.TrueForAll(l => l.IsReturned == true);

            string status = (available) ? "At home" : "Borrowed";

            var bookModel = new BookDetailsViewModel()
            {
                Title         = book.Title,
                Author        = authorName,
                Category      = categoryName,
                Description   = book.Description,
                CoverImageUrl = book.CoverImageUrl,
                Status        = status
            };

            return(View(bookModel));
        }
コード例 #9
0
        public BookDetailsViewModel SelectBook(int id)
        {
            string sql = "select BookId,BookName,ImageUrl,Price,Details from Books where BookId = @Id";

            using (SqlConnection conn = new SqlConnection(_connString))
            {
                conn.Open();
                using (SqlCommand cmd = new SqlCommand(sql, conn))
                {
                    cmd.Parameters.Add(new SqlParameter("@Id", id));
                    using (SqlDataReader reader = cmd.ExecuteReader())
                    {
                        if (reader.Read())
                        {
                            var book = new BookDetailsViewModel();
                            book.BookId   = reader.GetInt32(0);
                            book.BookName = reader.GetString(1);
                            book.ImageUrl = reader.GetString(2);
                            book.Price    = reader.GetDecimal(3);
                            book.Details  = reader.GetString(4);
                            return(book);
                        }
                    }
                }
            }
            return(null);
        }
コード例 #10
0
        public async Task <BookDetailsViewModel> GetBookDetailsAsync(int bookId, int userId)
        {
            var book = await _bookRepository.GetByIdAsync(bookId);

            var vm = new BookDetailsViewModel
            {
                BookId     = book.Id,
                Categories = book.BookCategories
                             .Select(bc => new CategoryViewModel {
                    Id = bc.CategoryId, Name = bc.Category.Name
                }),
                Authors       = book.BookAuthors.Select(b => b.Author.Name),
                Description   = book.Description,
                ImageUrl      = book.ImageUrlLarge,
                IsFavorite    = book.Favorites.Any(f => f.UserId == userId),
                Price         = book.Price,
                PublishedDate = book.PublishedDate,
                Publisher     = book.Publisher.Name,
                Title         = book.Title,
                Reviews       = book.Reviews.Select(r => new ReviewViewModel()
                {
                    Rating = r.Rating, ReviewText = r.ReviewText, UserName = r.User.UserName
                }),
                AverageRating = (decimal?)book.Reviews.Average(r => r.Rating)
            };

            return(vm);
        }
コード例 #11
0
        public IActionResult Details(int id)
        {
            BookDetailsViewModel bookDetailsViewModel = new BookDetailsViewModel();
            var book = _bookService.GetBy(id);

            if (book != null)
            {
                bookDetailsViewModel.Author        = book.Author;
                bookDetailsViewModel.Genre         = book.Genre.ToString();
                bookDetailsViewModel.Id            = book.Id;
                bookDetailsViewModel.NumberOfPages = book.NumberOfPages;
                bookDetailsViewModel.Price         = book.Price;
                bookDetailsViewModel.Title         = book.Title;
            }
            else
            {
                string na = "N/A";
                bookDetailsViewModel.Author        = na;
                bookDetailsViewModel.Genre         = na;
                bookDetailsViewModel.Id            = -1;
                bookDetailsViewModel.NumberOfPages = 0;
                bookDetailsViewModel.Price         = 0;
                bookDetailsViewModel.Title         = na;
            }
            return(View(bookDetailsViewModel));
        }
コード例 #12
0
        //NokkviKilla made this so this does work.
        //The function receives the details of one book.
        public IActionResult Details(int?id)
        {
            //This function takes in a bookID parameter which is the ID of the book that should have details.
            if (id == null)
            {
                //If a book is not specified, redirect to the not found page.
                return(View("NotFound"));
            }

            //Returns the BookViewModel of the book.
            var book = _bookService.GetBook((int)id);

            if (book == null)
            {
                return(View("NotFound"));
            }

            var ratings = _ratingService.GetRatings((int)id);

            var bookAndRatings = new BookDetailsViewModel()
            {
                Book    = book,
                Ratings = ratings,
            };

            //Returns the Details View for the book.
            return(View(bookAndRatings));
        }
コード例 #13
0
        public IActionResult BookDetails(int id)
        {
            var model = new BookDetailsViewModel();
            var user  = User.Identity.Name;

            model.Book = _myShelfDataService.GetBookById(id);

            model.GoodreadsList = _goodreadsService.GetBookBasedOnTitleInput(model.Book.Title);

            model.MyShelfBooks = _myShelfDataService.GetUserShelf(user);
            var templist = new List <int>();

            foreach (var book in model.MyShelfBooks)
            {
                templist.Add(book.Id);
            }
            ;

            if (templist.Contains(id))
            {
                model.Book.IsOnUserShelf = true;
            }

            return(View(model));
        }
コード例 #14
0
        public BookDetails(string id)
        {
            NavigationPage.SetHasNavigationBar(this, false);

            this.bookId = id;

            _model = new BookDetailsViewModel
            {
                Loading = true
            };

            this.BindingContext = _model;

            InitializeComponent();

            var book = AudioBookStore.Instance.GetMyAudioBook(id);

            if (book != null)
            {
                Download_OnProgress(book);
                AudioBookStore.Instance.OnProgress += Download_OnProgress;
            }
            else
            {
                _model.ShowCancel   = false;
                _model.ShowDownload = true;
                _model.ShowListen   = false;
                _model.ShowStatus   = false;
            }
        }
コード例 #15
0
        public IActionResult BookDetails(int libraryID)
        {
            IBook book = SearchUtility.GetBookByLibraryID(libraryID);
            BookDetailsViewModel viewModel = this.vmFactory.GetBookDetailsViewModel(book);

            return(View(viewModel));
        }
コード例 #16
0
        public IActionResult Details()
        {
            var model = new BookDetailsViewModel();

            model.Books    = _bookData.GetAll();
            model.Abstract = "Books Repository";
            return(View(model));
        }
コード例 #17
0
        public ActionResult Create()
        {
            var bookViewModel = new BookDetailsViewModel();

            bookViewModel.PublisherList = PublisherBLL.ListAll();
            bookViewModel.AuthorsList   = AuthorBLL.ListAll();
            return(View(bookViewModel));
        }
コード例 #18
0
        public IActionResult Details(int id)
        {
            var bookDetailsViewModel = new BookDetailsViewModel();

            bookDetailsViewModel.Book = bookService.GetBookDetails(id);

            return(View(bookDetailsViewModel));
        }
コード例 #19
0
        public IActionResult GetBooks()
        {
            var result = new BookDetailsViewModel();

            result.Books = _bookService.GetBooks();
            result.Types = _bookService.GetBookTypes();
            return(Ok(result));
        }
コード例 #20
0
        //Private Methods
        private BookDetailsViewModel GetBookDetailsViewModel(string id)
        {
            BookDetailsViewModel viewModel = new BookDetailsViewModel();

            viewModel.Book         = Utilities.GoogleBookSearchUtilities.ParseSingleSearchResponse(GoogleBooksAPIHandler.SingleSearch(id).Result);
            viewModel.Reviews      = db.Reviews.Include("Member").Where(r => r.BookId == viewModel.Book.Id).ToList();
            viewModel.RelatedBooks = GetRelatedBooks(viewModel.Book);
            return(viewModel);
        }
コード例 #21
0
        public IActionResult GetBookById(int bookId)
        {
            var book = bookRepository.GetBookById(bookId);

            if (book == null)
            {
                ModelState.AddModelError("", "Error retrieving a book");
                ViewBag.BookMessage = $"There are no book";
            }

            var categories = categoryRepository.GetCategoriesFromBook(bookId);

            if (categories.Count() <= 0)
            {
                ModelState.AddModelError("", "There are problems retrieving categories of a book");
            }

            var authors = authorRepository.GetAllAuthorsFromBook(book.Id);

            if (authors.Count() <= 0)
            {
                ModelState.AddModelError("", "There are problems retrieving authors of a book");
            }
            IDictionary <AuthorDto, CountryDto> authorCountry = new Dictionary <AuthorDto, CountryDto>();

            foreach (var author in authors)
            {
                var country = countryRepository.GetCountryOfAnAuthor(author.Id);
                authorCountry.Add(author, country);
            }

            var reviews = reviewRepository.GetReviewsFromBook(bookId);

            if (reviews.Count() <= 0)
            {
                ModelState.AddModelError("", "There are problems retrieving reviews of a book");
            }
            IDictionary <ReviewDto, ReviewerDto> reviewReviewer = new Dictionary <ReviewDto, ReviewerDto>();

            foreach (var review in reviews)
            {
                var reviewer = reviewerRepository.GetReviewerPerReviews(review.Id);
                reviewReviewer.Add(review, reviewer);
            }
            decimal rating = bookRepository.BookRating(bookId);
            BookDetailsViewModel bookDetails = new BookDetailsViewModel()
            {
                Book            = book,
                Categories      = categories,
                AuthorsCountry  = authorCountry,
                ReviewsReviewer = reviewReviewer,
                Rating          = rating
            };

            return(View(bookDetails));
        }
コード例 #22
0
        void NavigaeteToBookDetails(Book book)
        {
            var detailsViewModel  = new BookDetailsViewModel(book);
            var storyBoard        = UIStoryboard.FromName("Main", null);
            var detailsController = storyBoard.InstantiateViewController("BookDetailsViewController") as BookDetailsViewController;

            detailsController.viewModel      = detailsViewModel;
            detailsController.didUpdateBook += DidUpdateBook;
            NavigationController.PushViewController(detailsController, true);
        }
コード例 #23
0
        public IActionResult Delete(int?id)
        {
            BookDetailsViewModel bookDetailsVM = new BookDetailsViewModel()
            {
                Book      = _bookRepository.GetBook(id ?? 1),
                PageTitle = "Are you sure want to delete this book?"
            };

            return(View(bookDetailsVM));
        }
コード例 #24
0
        public ActionResult Details(int id)
        {
            Book                 thisBook = _db.Books.Include(book => book.Authors).ThenInclude(entry => entry.Author).FirstOrDefault(book => book.BookId == id);
            List <Author>        authors  = thisBook.Authors.Select(entry => entry.Author).ToList();
            BookDetailsViewModel model    = new BookDetailsViewModel()
            {
                Book = thisBook, Authors = authors
            };

            return(View(model));
        }
コード例 #25
0
        public IActionResult RemoveBookFromUserShelf(BookDetailsViewModel model)
        {
            var userName = User.Identity.Name;

            if (ModelState.IsValid)
            {
                _myShelfDataService.RemoveBookFromUserShelf(userName, model.Book);
            }

            return(RedirectToAction("BookDetails", new { id = model.Book.Id }));
        }
コード例 #26
0
 public IActionResult Details(int?id)
 {
     if (id != null)
     {
         // if we send id find the book we are looking for
         Book book = StaticDb.Books.FirstOrDefault(x => x.Id == id);
         BookDetailsViewModel bookDetailsViewModel = BookMapper.ToBookDetailsViewModel(book);
         return(View(bookDetailsViewModel));
     }
     return(new EmptyResult());
 }
コード例 #27
0
ファイル: BooksController.cs プロジェクト: MeGaDeTH91/SoftUni
        public IActionResult DeleteBook(int id)
        {
            BookDetailsViewModel book = this.bookService.GetBook(id);

            if (book == null)
            {
                return(RedirectToAction(RedirectConstants.IndexSuffix));
            }

            return(this.View(book));
        }
コード例 #28
0
        public IActionResult Details(int id)
        {
            var model = new BookDetailsViewModel();

            model.Book = bookService.GetBookById(id);
            if (model.Book == null)
            {
                return(View("NotFound"));
            }
            return(View(model));
        }
コード例 #29
0
        public BookDetailsPage(BookDetailsViewModel bookDetailsViewModel)
        {
            InitializeComponent();

            BindingContext = bookDetailsViewModel;

            btnBack.Clicked += BtnBack_Clicked;

            //ExitCommand = new Command(async () => await Navigation.PopAsync());
            //ExitCommand = new Command(async () => await Application.Current.MainPage.Navigation.PopAsync());
        }
コード例 #30
0
        public IActionResult Details(int id)
        {
            var bookDetailsViewModel = new BookDetailsViewModel();

            bookDetailsViewModel.Book = bookService.GetBookDetails(id);
            if (bookDetailsViewModel.Book.DonationStatus != "Not for Donation")
            {
                bookDetailsViewModel.RecipientName = recipientService.GetRecipientName(id);
            }

            return(View(bookDetailsViewModel));
        }