public async Task <DynamicContentPublicationSearchResult> SearchContentPublicationsAsync(DynamicContentPublicationSearchCriteria criteria) { var cacheKey = CacheKey.With(GetType(), "SearchContentPublicationsAsync", criteria.GetCacheKey()); return(await _platformMemoryCache.GetOrCreateExclusiveAsync(cacheKey, async (cacheEntry) => { cacheEntry.AddExpirationToken(DynamicContentPublicationCacheRegion.CreateChangeToken()); var retVal = AbstractTypeFactory <DynamicContentPublicationSearchResult> .TryCreateInstance(); using (var repository = _repositoryFactory()) { var query = repository.PublishingGroups; if (!string.IsNullOrEmpty(criteria.Store)) { query = query.Where(x => x.StoreId == criteria.Store); } if (criteria.OnlyActive) { query = query.Where(x => x.IsActive == true); } if (!string.IsNullOrEmpty(criteria.Keyword)) { query = query.Where(q => q.Name.Contains(criteria.Keyword)); } var sortInfos = criteria.SortInfos; if (sortInfos.IsNullOrEmpty()) { sortInfos = new[] { new SortInfo { SortColumn = ReflectionUtility.GetPropertyName <DynamicContentPublication>(x => x.Name), SortDirection = SortDirection.Ascending } }; } query = query.OrderBySortInfos(sortInfos); retVal.TotalCount = await query.CountAsync(); if (criteria.Take > 0) { var ids = await query.Select(x => x.Id).Skip(criteria.Skip).Take(criteria.Take).ToArrayAsync(); retVal.Results = await _dynamicContentService.GetPublicationsByIdsAsync(ids); } } return retVal; })); }
public async Task <DynamicContentPublicationSearchResult> SearchContentPublicationsAsync(DynamicContentPublicationSearchCriteria criteria) { var cacheKey = CacheKey.With(GetType(), nameof(SearchContentPublicationsAsync), criteria.GetCacheKey()); return(await _platformMemoryCache.GetOrCreateExclusiveAsync(cacheKey, async (cacheEntry) => { cacheEntry.AddExpirationToken(DynamicContentPublicationCacheRegion.CreateChangeToken()); var retVal = AbstractTypeFactory <DynamicContentPublicationSearchResult> .TryCreateInstance(); using (var repository = _repositoryFactory()) { var sortInfos = BuildSortExpression(criteria); var query = BuildQuery(criteria, repository); retVal.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(); retVal.Results = (await _dynamicContentService.GetPublicationsByIdsAsync(ids)) .OrderBy(x => Array.IndexOf(ids, x.Id)).ToList(); } } return retVal; })); }