public async Task <CustomerReviewSearchResult> SearchCustomerReviewsAsync(CustomerReviewSearchCriteria criteria)
        {
            var cacheKey = CacheKey.With(GetType(), nameof(SearchCustomerReviewsAsync), criteria.GetCacheKey());

            return(await _platformMemoryCache.GetOrCreateExclusiveAsync(cacheKey, async (cacheEntry) =>
            {
                cacheEntry.AddExpirationToken(CustomerReviewCacheRegion.CreateChangeToken());
                var result = AbstractTypeFactory <CustomerReviewSearchResult> .TryCreateInstance();
                using (var repository = _repositoryFactory())
                {
                    var query = BuildQuery(repository, criteria);
                    var sortInfos = BuildSortExpression(criteria);

                    result.TotalCount = await query.CountAsync();
                    if (criteria.Take > 0)
                    {
                        var customerReviewIds = await query.OrderBySortInfos(sortInfos).ThenBy(x => x.Id)
                                                .Select(x => x.Id)
                                                .Skip(criteria.Skip).Take(criteria.Take)
                                                .ToArrayAsync();

                        var unorderedResults = await _customerReviewService.GetByIdsAsync(customerReviewIds);
                        result.Results = unorderedResults.OrderBy(x => Array.IndexOf(customerReviewIds, x.Id)).ToArray();
                    }
                }
                return result;
            }));
        }
Beispiel #2
0
        public virtual async Task <CustomerReview[]> GetByIdsAsync(string[] ids)
        {
            var cacheKey = CacheKey.With(GetType(), "GetByIdsAsync", string.Join("-", ids));

            return(await _platformMemoryCache.GetOrCreateExclusiveAsync(cacheKey, async (cacheEntry) =>
            {
                cacheEntry.AddExpirationToken(CustomerReviewCacheRegion.CreateChangeToken());

                using (var repository = _repositoryFactory())
                {
                    repository.DisableChangesTracking();

                    return (await repository.GetByIdsAsync(ids)).Select(x => x.ToModel(AbstractTypeFactory <CustomerReview> .TryCreateInstance())).ToArray();
                }
            }));
        }