示例#1
0
        public ReviewsViewModel Get(string productCode)
        {
            return(_cache.ReadThrough(CachePrefix + productCode, () =>
            {
                // Instantiate a reference for the product
                var product = Reference.Create($"product://{productCode}");

                try
                {
                    // Retrieve the rating statistics for the product
                    var statistics = GetProductStatistics(product);

                    // Retrieve the reviews for the product
                    var reviews = GetProductReviews(product);

                    // Return the data as a ReviewsViewModel
                    return new ReviewsViewModel
                    {
                        Statistics = ViewModelAdapter.Adapt(statistics),
                        Reviews = ViewModelAdapter.Adapt(reviews)
                    };
                }
                catch (SocialRepositoryException)
                {
                    //DO SOMETHING
                }

                return new ReviewsViewModel();
            },
                                      (x) => new CacheEvictionPolicy(TimeSpan.FromMinutes(15), CacheTimeoutType.Absolute),
                                      ReadStrategy.Wait));
        }
示例#2
0
        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));
        }
示例#3
0
        public ReviewsViewModel Get(string productCode)
        {
            // Instantiate a reference for the product
            var product = Reference.Create($"product://{productCode}");

            try
            {
                // Retrieve the rating statistics for the product
                var statistics = GetProductStatistics(product);

                // Retrieve the reviews for the product
                var reviews = GetProductReviews(product);

                // Return the data as a ReviewsViewModel
                return(new ReviewsViewModel
                {
                    Statistics = ViewModelAdapter.Adapt(statistics),
                    Reviews = ViewModelAdapter.Adapt(reviews)
                });
            }
            catch (SocialRepositoryException)
            {
                //DO SOMETHING
            }

            return(new ReviewsViewModel());
        }
示例#4
0
        public IEnumerable <ReviewStatisticsViewModel> GetRatings(IEnumerable <string> productCodes)
        {
            //ResultPage<Composite<RatingStatistics, Review>> statistics = null;
            ResultPage <RatingStatistics> statistics = null;

            var statisticsCriteria = new Criteria <RatingStatisticsFilter>
            {
                Filter = new RatingStatisticsFilter
                {
                    Targets = productCodes.Select(x => Reference.Create($"product://{x}"))
                },
                PageInfo = new PageInfo
                {
                    PageSize = productCodes.Count()
                }
            };

            try
            {
                statistics = _ratingStatisticsService.Get(statisticsCriteria);

                if (!statistics.Results.Any())
                {
                    return(new List <ReviewStatisticsViewModel>());
                }
            }
            catch (SocialAuthenticationException ex)
            {
                throw new SocialRepositoryException("The application failed to authenticate with Episerver Social.",
                                                    ex);
            }
            catch (MaximumDataSizeExceededException ex)
            {
                throw new SocialRepositoryException(
                          "The application request was deemed too large for Episerver Social.", ex);
            }
            catch (SocialCommunicationException ex)
            {
                throw new SocialRepositoryException("The application failed to communicate with Episerver Social.", ex);
            }
            catch (SocialException ex)
            {
                throw new SocialRepositoryException("Episerver Social failed to process the application request.", ex);
            }

            return(statistics.Results.Select(x => ViewModelAdapter.Adapt(x)));
        }
示例#5
0
        private IEnumerable <ReviewViewModel> GetComments(Visibility visibility, int page, int limit, out long total)
        {
            var criteria = new Criteria <CommentFilter>
            {
                Filter = new CommentFilter
                {
                    Visibility = visibility
                },
                PageInfo = new PageInfo
                {
                    PageSize            = limit,
                    CalculateTotalCount = true,
                    PageOffset          = (page - 1) * limit
                },
                OrderBy = new List <SortInfo>
                {
                    new SortInfo(CommentSortFields.Created, false)
                }
            };

            try
            {
                var result = new List <ReviewViewModel>();
                var cmts   = _commentService.Get(criteria);
                total = cmts.TotalCount;
                foreach (var cmt in cmts.Results)
                {
                    if (cmt.Parent.Id.IndexOf("product") > -1)
                    {
                        try
                        {
                            var review = _commentService.Get <Review>(cmt.Id);
                            result.Add(ViewModelAdapter.Adapt(review));
                        }
                        catch
                        {
                            result.Add(new ReviewViewModel
                            {
                                AddedOnStr = cmt.Created.ToString("MM/dd/yyyy hh:mm:ss"),
                                AddedOn    = cmt.Created,
                                Body       = cmt.Body,
                                Location   = "",
                                Nickname   = "",
                                Rating     = 0,
                                Title      = "",
                                Id         = cmt.Id,
                                Parent     = cmt.Parent,
                                Author     = cmt.Author,
                                IsVisible  = cmt.IsVisible
                            });
                        }
                    }
                    else
                    {
                        result.Add(new ReviewViewModel
                        {
                            AddedOnStr = cmt.Created.ToString("MM/dd/yyyy hh:mm:ss"),
                            AddedOn    = cmt.Created,
                            Body       = cmt.Body,
                            Location   = "",
                            Nickname   = "",
                            Rating     = 0,
                            Title      = "",
                            Id         = cmt.Id,
                            Parent     = cmt.Parent,
                            Author     = cmt.Author,
                            IsVisible  = cmt.IsVisible
                        });
                    }
                }

                return(result);
            }
            catch (SocialAuthenticationException ex)
            {
                throw new SocialRepositoryException("The application failed to authenticate with Episerver Social.",
                                                    ex);
            }
            catch (MaximumDataSizeExceededException ex)
            {
                throw new SocialRepositoryException(
                          "The application request was deemed too large for Episerver Social.", ex);
            }
            catch (SocialCommunicationException ex)
            {
                throw new SocialRepositoryException("The application failed to communicate with Episerver Social.", ex);
            }
            catch (SocialException ex)
            {
                throw new SocialRepositoryException("Episerver Social failed to process the application request.", ex);
            }
        }