public IActionResult GetReviewById(int reviewId) { var review = _reviewRepository.GetReviewById(reviewId); if (review == null) { ModelState.AddModelError("", "Some kind of error getting review"); ViewBag.Message = $"There was a problem retrieving review from the " + $"database or no review with id {reviewId} exists"; review = new ReviewDto(); } var reviewer = _reviewerRepository.GetReviewerOfAReview(reviewId); if (reviewer == null) { ModelState.AddModelError("", "Some kind of error getting reviewer"); ViewBag.Message += $"There was a problem retrieving reviewer from the database " + $"or no reviewer for the review id {reviewId} exist"; reviewer = new ReviewerDto(); } var book = _reviewRepository.GetBookOfAReview(reviewId); if (book == null) { ModelState.AddModelError("", "Some kind of error getting book"); ViewBag.Message += $"There was a problem retrieving book from the database " + $"or no book for the review id {reviewId} exist"; book = new BookDto(); } var reviewReviewerBookViewModel = new ReviewReviewerBookViewModel { Review = review, Reviewer = reviewer, Book = book }; ViewBag.SuccessMessage = TempData["SuccessMessage"]; return(View(reviewReviewerBookViewModel)); }
public IActionResult GetReviewById(int reviewId) { var review = _reviewRepository.GetReviewById(reviewId); if (review == null) { ModelState.AddModelError("", "Error getting a review"); ViewBag.Review = $"There was a problem retrieving review with Id={reviewId} " + $"from the database or no review with this id exists"; review = new ReviewDto(); } var reviewer = _reviewerRepository.GetReviewerOfAReview(reviewId); if (reviewer == null) { ModelState.AddModelError("", "Error getting a reviewer"); ViewBag.Reviewer = $"There was a problem retrieving reviewer of review Id={reviewId} " + $"from the database or no reviewer exists"; reviewer = new ReviewerDto(); } var book = _reviewRepository.GetBookOfAReview(reviewId); if (book == null) { ModelState.AddModelError("", "Error getting a book"); ViewBag.Book = $"There was a problem retrieving book of review Id={reviewId} " + $"from the database or no book exists"; book = new BookDto(); } var reviewReviewerBookViewModel = new ReviewReviewerBookViewModel() { Review = review, Reviewer = reviewer, Book = book }; return(View(reviewReviewerBookViewModel)); }