Пример #1
0
        public IActionResult GetReviewById(int reviewId)
        {
            var review = reviewRepository.GetReview(reviewId);

            if (review == null)
            {
                ModelState.AddModelError("", "Error getting a review");
                ViewBag.Message = $"There was a problem retrieving review id {reviewId}" +
                                  $" from the database or no review with id exists.";

                review = new ReviewDto();
            }

            var reviewer = reviewerRepository.GetReviewerPerReviews(reviewId);

            if (reviewer == null)
            {
                ModelState.AddModelError("", "Error getting a reviewer");
                ViewBag.Message += $"There was a problem retrieving reviewer " +
                                   $"or there is no reviewer exists from review id {reviewId}.";

                reviewer = new ReviewerDto();
            }

            var book = reviewRepository.GetBookFromReview(reviewId);

            if (book == null)
            {
                ModelState.AddModelError("", "Error getting a book");
                ViewBag.Message += $"There was a problem retrieving book" +
                                   $"or there is no book exists from review id {reviewId}.";

                book = new BookDto();
            }

            var reviewReviewerBookViewModel = new ReviewReviewerBook()
            {
                Review   = review,
                Reviewer = reviewer,
                Book     = book
            };

            return(View(reviewReviewerBookViewModel));
        }
Пример #2
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));
        }