public ReviewViewModel Add(ReviewSubmissionViewModel review)
        {
            // Instantiate a reference for the product
            var product = Reference.Create($"product://{review.ProductCode}");

            // Instantiate a reference for the contributor
            var contributor = Reference.Create($"visitor://{review.Nickname}");

            // Add the contributor's rating for the product
            var submittedRating = new Rating(contributor, product, new RatingValue(review.Rating));
            var storedRating    = _ratingService.Add(submittedRating);

            // Compose a comment representing the review
            var comment   = new Comment(product, contributor, review.Body, true);
            var extension = new Review
            {
                Title    = review.Title,
                Location = review.Location,
                Nickname = review.Nickname,
                Rating   = new ReviewRating
                {
                    Value     = review.Rating,
                    Reference = storedRating.Id.Id
                }
            };

            var result = _commentService.Add(comment, extension);

            _cache.Remove(CachePrefix + review.ProductCode);
            // Add the composite comment for the product
            return(ViewModelAdapter.Adapt(result));
        }
Exemple #2
0
        /// <summary>
        /// Adds a review for the identified product.
        /// </summary>
        /// <param name="productCode">Content code identifying the product being reviewed</param>
        /// <param name="review">Review to be added</param>
        public void Add(ReviewSubmissionViewModel review)
        {
            // Instantiate a reference for the product

            var product = CreateProductReference(review.ProductCode);

            // Instantiate a reference for the contributor

            var contributor = CreateContributorReference(review.Nickname);

            // Add the contributor's rating for the product

            var submittedRating = new Rating(contributor, product, new RatingValue(review.Rating));
            var storedRating    = this.ratingService.Add(submittedRating);

            // Compose a comment representing the review

            var comment = new Comment(product, contributor, review.Body, true);

            var extension = new Review
            {
                Title    = review.Title,
                Location = review.Location,
                Nickname = review.Nickname,
                Rating   = new ReviewRating
                {
                    Value     = review.Rating,
                    Reference = storedRating.Id.Id
                }
            };

            // Add the composite comment for the product

            this.commentService.Add(comment, extension);
        }
 public ActionResult AddAReview(ReviewSubmissionViewModel reviewForm)
 {
     // Invoke the ReviewService to add the submission
     try
     {
         var model = _reviewService.Add(reviewForm);
         //Loyalty Program: Add Points and Number Of Reviews
         _loyaltyService.AddNumberOfReviews();
         AddActivity(reviewForm.ProductCode, reviewForm.Rating, reviewForm.Nickname);
         return(PartialView("_ReviewItem", model));
     }
     catch (Exception e)
     {
         return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, e.Message));
     }
 }
        public ActionResult AddAReview(ReviewSubmissionViewModel reviewForm)
        {
            _reviewService.Add(reviewForm);

            return(RedirectToAction("Index"));
        }