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)); }
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)); }