Exemple #1
0
        public IHttpActionResult SearchCustomerReviews([FromBody] CustomerReviewSearchCriteria criteria)

        {
            GenericSearchResult <CustomerReview> result = _customerReviewSearchService.SearchCustomerReviews(criteria);

            return(Ok(result));
        }
Exemple #2
0
        /// <summary>
        /// Gets the aggregated product rating based on formula from https://habr.com/post/172065/
        /// </summary>
        /// <param name="productId"></param>
        /// <returns></returns>
        public decimal GetProductRating(string productId)
        {
            if (string.IsNullOrEmpty(productId))
            {
                throw new ArgumentNullException(nameof(productId));
            }

            var result = 0m;

            //Read all items at once in this demo project
            var searchResult = reviewSearchService.SearchCustomerReviews(new Core.Model.CustomerReviewSearchCriteria()
            {
                ProductIds = new string[] { productId },
                HasRating  = true,
            });

            if (searchResult != null && searchResult.TotalCount > 0)
            {
                var specificProductReviews      = searchResult.Results.ToList();
                var specificProductReviewsCount = specificProductReviews.Count;
                if (specificProductReviewsCount >= MinReviewCountLimit)
                {
                    //rating = (V*R + M*C)/(V+M)
                    //Where
                    //V – This product review count
                    //M – Review count limit for product to have rating
                    //R – Average rating for this product
                    //С – Average rating for all products

                    var specificAverage = specificProductReviews.Average(x => x.Rating);

                    //Getting all in one butch for now
                    var allReviewAverageRating = reviewSearchService.SearchCustomerReviews(new Core.Model.CustomerReviewSearchCriteria()
                    {
                    }).Results.Average(x => x.Rating);

                    result = (decimal)(specificProductReviewsCount * specificAverage + MinReviewCountLimit * allReviewAverageRating) / (specificProductReviewsCount + MinReviewCountLimit);
                }
            }
            return(result);
        }
Exemple #3
0
        public void SearchCustomerReviewsTest()
        {
            // Arrange
            var criteria = new CustomerReviewSearchCriteria
            {
                IsActive   = true,
                ProductIds = new string[1] {
                    _testProductId
                }
            };

            // Act
            GenericSearchResult <CustomerReview> result = _customerReviewSearchService.SearchCustomerReviews(criteria);

            // Assert
            Assert.Equal(1, result.TotalCount);
        }
        protected override ExportableSearchResult FetchData(CustomerReviewSearchCriteria searchCriteria)
        {
            CustomerReview[] result;
            int totalCount;

            if (searchCriteria.ObjectIds.Any(x => !string.IsNullOrWhiteSpace(x)))
            {
                result     = _customerReviewService.GetByIds(Enumerable.ToArray(searchCriteria.ObjectIds));
                totalCount = result.Length;
            }
            else
            {
                var priceSearchResult = _searchService.SearchCustomerReviews(searchCriteria);
                result     = priceSearchResult.Results.ToArray();
                totalCount = priceSearchResult.TotalCount;
            }

            return(new ExportableSearchResult
            {
                Results = ToExportable(result).ToList(),
                TotalCount = totalCount,
            });
        }
Exemple #5
0
        public IHttpActionResult SearchCustomerReviews(CustomerReviewSearchCriteria criteria)
        {
            var result = _customerReviewSearchService.SearchCustomerReviews(criteria);

            return(Ok(result));
        }