コード例 #1
0
        public ActionResult CreateReview(CreateReviewViewModel vm, int pMediaId)
        {
            vm.mediaId = pMediaId;
            Media media = CatalogueService.GetMediaById(pMediaId);

            vm.Item = media;
            User currentUser = UserService.GetUserByUserName(HttpContext.User.Identity.Name);

            vm.AuthorId = currentUser.Id;

            // Get the Review Message Type
            var reviewMessage = vm.toMessageType();

            // Update the rating sum and count on the media
            media.RatingCount++;
            media.RatingSum += vm.Rating;

            // Save the review to the database
            ServiceFactory.Instance.ReviewService.SubmitReview(reviewMessage, media, currentUser);

            // Go back to the media details page
            return(RedirectToAction("ShowDetails", "Details", routeValues: new { mediaId = pMediaId }));
        }