public IActionResult GetReviewerById(int reviewerId)
        {
            var reviewer = _reviewerRepository.GetReviewerById(reviewerId);

            if (reviewer == null)
            {
                ModelState.AddModelError("", "Some kind of error getting reviewer");
                ViewBag.ReviewerMessage = $"There was a problem retrieving reviewer with id {reviewerId} " +
                                          $"From the database or no reviewer with that id exists";
                reviewer = new ReviewerDto();
            }

            var reviews = _reviewerRepository.GetReviewsByReviewer(reviewerId);

            if (reviews.Count() <= 0)
            {
                ViewBag.ReviewMessage = $"Reviewer {reviewer.FirstName} {reviewer.LastName} has no reviews";
            }

            IDictionary <ReviewDto, BookDto> reviewAndBook = new Dictionary <ReviewDto, BookDto>();

            foreach (var review in reviews)
            {
                var book = _reviewRepository.GetBookOfAReview(review.Id);
                reviewAndBook.Add(review, book);
            }

            var reviewerReviewsBooksViewModel = new ReviewerReviewsBooksViewModel()
            {
                Reviewer   = reviewer,
                ReviewBook = reviewAndBook
            };

            ViewBag.SuccessMessage = TempData["SuccessMessage"];
            return(View(reviewerReviewsBooksViewModel));
        }
Ejemplo n.º 2
0
        public IActionResult DetailReviewer(int reviewerId)
        {
            var reviewer = reviewerRepository.GetReviewer(reviewerId);

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

                reviewer = new ReviewerDto();
            }

            var reviews = reviewerRepository.GetReviewsByReviewer(reviewerId);

            if (reviews.Count() <= 0)
            {
                ViewBag.ReviewMessage = $"{reviewer.LastName}, {reviewer.FirstName} has no reviewss.";
            }

            IDictionary <ReviewDto, BookDto> ReviewsAdnBooks = new Dictionary <ReviewDto, BookDto>();

            foreach (var review in reviews)
            {
                var book = reviewRepository.GetBookFromReview(review.Id);
                ReviewsAdnBooks.Add(review, book);
            }

            var reviewerReviewsBookModel = new ReviewerReviewsBooksViewModel()
            {
                Reviewer   = reviewer,
                ReviewBook = ReviewsAdnBooks
            };

            return(View(reviewerReviewsBookModel));
        }