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; })); }
public IHttpActionResult DynamicContentPlaceListEntriesSearch(DynamicContentPlaceSearchCriteria criteria) { var retVal = new GenericSearchResult <webModel.DynamicContentListEntry>(); retVal.Results = new List <webModel.DynamicContentListEntry>(); var foldersSearchResult = _dynamicConentSearchService.SearchFolders(new DynamicContentFolderSearchCriteria { FolderId = criteria.FolderId, Keyword = criteria.Keyword, Take = criteria.Take, Skip = criteria.Skip, Sort = criteria.Sort }); var folderSkip = Math.Min(foldersSearchResult.TotalCount, criteria.Skip); var folderTake = Math.Min(criteria.Take, Math.Max(0, foldersSearchResult.TotalCount - criteria.Skip)); var folders = foldersSearchResult.Results.Skip(folderSkip).Take(folderTake).Select(x => x.ToWebModel()); retVal.TotalCount += foldersSearchResult.TotalCount; retVal.Results.AddRange(folders); criteria.Skip = criteria.Skip - folderSkip; criteria.Take = criteria.Take - folderTake; var placesSearchResult = _dynamicConentSearchService.SearchContentPlaces(criteria); retVal.TotalCount += placesSearchResult.TotalCount; retVal.Results.AddRange(placesSearchResult.Results.Select(x => x.ToWebModel())); return(Ok(retVal)); }
public IHttpActionResult DynamicContentPlacesSearch(DynamicContentPlaceSearchCriteria criteria) { var retVal = new GenericSearchResult <webModel.DynamicContentPlace>(); var placesSearchResult = _dynamicConentSearchService.SearchContentPlaces(criteria); retVal.TotalCount = placesSearchResult.TotalCount; retVal.Results = placesSearchResult.Results.Select(x => x.ToWebModel()).ToList(); return(Ok(retVal)); }
protected virtual IQueryable <DynamicContentPlaceEntity> BuildQuery(DynamicContentPlaceSearchCriteria criteria, IMarketingRepository repository) { 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)); } return(query); }
protected virtual IList <SortInfo> BuildSearchExpression(DynamicContentPlaceSearchCriteria criteria) { var sortInfos = criteria.SortInfos; if (sortInfos.IsNullOrEmpty()) { sortInfos = new[] { new SortInfo { SortColumn = nameof(DynamicContentPlace.Name), SortDirection = SortDirection.Ascending } }; } return(sortInfos); }
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; })); }
public GenericSearchResult <coreModel.DynamicContentPlace> SearchContentPlaces(DynamicContentPlaceSearchCriteria criteria) { var retVal = new GenericSearchResult <coreModel.DynamicContentPlace>(); 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 <coreModel.DynamicContentPlace>(x => x.Name), SortDirection = SortDirection.Ascending } }; } query = query.OrderBySortInfos(sortInfos); retVal.TotalCount = query.Count(); var ids = query.Select(x => x.Id) .Skip(criteria.Skip) .Take(criteria.Take).ToArray(); retVal.Results = _dynamicContentService.GetPlacesByIds(ids); } return(retVal); }
protected virtual GenericSearchResult <DynamicContentPlace> LoadContentPlaces(DynamicContentPlaceSearchCriteria criteria) { return(_dynamicContentSearchService.SearchContentPlaces(criteria)); }