protected virtual void ClearCache(IEnumerable <QuoteRequest> items) { QuoteSearchCacheRegion.ExpireRegion(); foreach (var item in items.Where(x => !x.IsTransient())) { QuoteCacheRegion.Expire(item.Id); } }
public async Task <QuoteRequestSearchResult> SearchAsync(QuoteRequestSearchCriteria criteria) { var result = new QuoteRequestSearchResult(); var cacheKey = CacheKey.With(GetType(), nameof(SearchAsync), criteria.GetCacheKey()); return(await _platformMemoryCache.GetOrCreateExclusiveAsync(cacheKey, async cacheEntry => { cacheEntry.AddExpirationToken(QuoteSearchCacheRegion.CreateChangeToken()); using (var repository = _repositoryFactory()) { var query = repository.QuoteRequests; if (criteria.CustomerId != null) { query = query.Where(x => x.CustomerId == criteria.CustomerId); } if (criteria.StoreId != null) { query = query.Where(x => x.StoreId == criteria.StoreId); } if (criteria.Number != null) { query = query.Where(x => x.Number == criteria.Number); } else if (criteria.Keyword != null) { query = query.Where(x => x.Number.Contains(criteria.Keyword) || (x.CustomerName != null && x.CustomerName.Contains(criteria.Keyword)) || (x.Status != null && x.Status.Contains(criteria.Keyword))); } if (criteria.Tag != null) { query = query.Where(x => x.Tag == criteria.Tag); } if (criteria.Status != null) { query = query.Where(x => x.Status == criteria.Status); } var sortInfos = criteria.SortInfos; if (sortInfos.IsNullOrEmpty()) { sortInfos = new[] { new SortInfo { SortColumn = ReflectionUtility.GetPropertyName <QuoteRequest>(x => x.CreatedDate), SortDirection = SortDirection.Descending } }; } result.TotalCount = await query.CountAsync(); if (criteria.Take > 0) { var ids = await query.OrderBySortInfos(sortInfos).ThenBy(x => x.Id) .Select(x => x.Id) .Skip(criteria.Skip).Take(criteria.Take) .ToArrayAsync(); result.Results = (await GetByIdsAsync(ids)).OrderBy(x => Array.IndexOf(ids, x.Id)).ToList(); } } return result; })); }