Beispiel #1
0
        public async Task <DynamicContentPlaceSearchResult> SearchContentPlacesAsync(DynamicContentPlaceSearchCriteria criteria)
        {
            var cacheKey = CacheKey.With(GetType(), "SearchContentPlacesAsync", criteria.GetCacheKey());

            return(await _platformMemoryCache.GetOrCreateExclusiveAsync(cacheKey, async (cacheEntry) =>
            {
                cacheEntry.AddExpirationToken(DynamicContentPlaceCacheRegion.CreateChangeToken());
                var retVal = AbstractTypeFactory <DynamicContentPlaceSearchResult> .TryCreateInstance();
                using (var repository = _repositoryFactory())
                {
                    var query = repository.Places;
                    if (!string.IsNullOrEmpty(criteria.FolderId))
                    {
                        query = query.Where(x => x.FolderId == criteria.FolderId);
                    }
                    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 <DynamicContentPlace>(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.GetPlacesByIdsAsync(ids);
                    }
                }
                return retVal;
            }));
        }
Beispiel #2
0
        public async Task <DynamicContentPlaceSearchResult> SearchContentPlacesAsync(DynamicContentPlaceSearchCriteria criteria)
        {
            var cacheKey = CacheKey.With(GetType(), nameof(SearchContentPlacesAsync), criteria.GetCacheKey());

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

                    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 _dynamicContentService.GetPlacesByIdsAsync(ids))
                                         .OrderBy(x => Array.IndexOf(ids, x.Id)).ToList();
                    }
                }
                return result;
            }));
        }