#pragma warning disable S4457 // Parameter validation in "async"/"await" methods should be wrapped public virtual async Task <PromotionUsageSearchResult> SearchUsagesAsync(PromotionUsageSearchCriteria criteria) #pragma warning restore S4457 // Parameter validation in "async"/"await" methods should be wrapped { if (criteria == null) { throw new ArgumentNullException(nameof(criteria)); } var cacheKey = CacheKey.With(GetType(), nameof(SearchUsagesAsync), criteria.GetCacheKey()); return(await _platformMemoryCache.GetOrCreateExclusiveAsync(cacheKey, async (cacheEntry) => { cacheEntry.AddExpirationToken(PromotionUsageSearchCacheRegion.CreateChangeToken()); var result = AbstractTypeFactory <PromotionUsageSearchResult> .TryCreateInstance(); using (var repository = _repositoryFactory()) { var sortInfos = BuildSortExpression(criteria); var query = BuildQuery(repository, criteria); result.TotalCount = await query.CountAsync(); if (criteria.Take > 0) { var usages = await query.OrderBySortInfos(sortInfos).ThenBy(x => x.Id) .Skip(criteria.Skip).Take(criteria.Take) .ToArrayAsync(); result.Results = usages.Select(x => x.ToModel(AbstractTypeFactory <PromotionUsage> .TryCreateInstance())).ToList(); } return result; } })); }
public virtual async Task <GenericSearchResult <PromotionUsage> > SearchUsagesAsync(PromotionUsageSearchCriteria criteria) { if (criteria == null) { throw new ArgumentNullException(nameof(criteria)); } var cacheKey = CacheKey.With(GetType(), "SearchUsagesAsync", criteria.GetCacheKey()); return(await _platformMemoryCache.GetOrCreateExclusiveAsync(cacheKey, async (cacheEntry) => { cacheEntry.AddExpirationToken(PromotionUsageCacheRegion.CreateChangeToken()); using (var repository = _repositoryFactory()) { var query = GetPromotionUsageQuery(repository, criteria); var sortInfos = criteria.SortInfos; if (sortInfos.IsNullOrEmpty()) { sortInfos = new[] { new SortInfo { SortColumn = ReflectionUtility.GetPropertyName <PromotionUsage>(x => x.ModifiedDate), SortDirection = SortDirection.Descending } }; } query = query.OrderBySortInfos(sortInfos); var totalCount = await query.CountAsync(); var searchResult = new GenericSearchResult <PromotionUsage> { TotalCount = totalCount }; if (criteria.Take > 0) { var coupons = await query.Skip(criteria.Skip).Take(criteria.Take).ToArrayAsync(); searchResult.Results = coupons.Select(x => x.ToModel(AbstractTypeFactory <PromotionUsage> .TryCreateInstance())).ToList(); } return searchResult; } })); }