示例#1
0
        protected virtual Task LoadProductCustomerReviewsAsync(List <Product> products, WorkContext workContext)
        {
            if (products == null)
            {
                throw new ArgumentException(nameof(products));
            }

            foreach (var product in products)
            {
                product.CustomerReviews = new MutablePagedList <Model.CustomerReviews.CustomerReview>((pageNumber, pageSize, sortInfos, @params) =>
                {
                    var criteria = new CustomerReviewSearchCriteria
                    {
                        ProductIds = new[] { product.Id },
                        PageNumber = pageNumber,
                        PageSize   = pageSize,
                        Sort       = SortInfo.ToString(sortInfos)
                    };
                    return(_customerReviewService.SearchReview(criteria));
                }, 1, CustomerReviewSearchCriteria.DefaulePageSize);
                product.Rating = _customerReviewService.GetProductRating(product.Id);
            }
            return(Task.CompletedTask);
        }