private async Task <IPagedList <Category> > InnerSearchCategoriesAsync(CategorySearchCriteria criteria, WorkContext workContext)
        {
            criteria = criteria.Clone();
            var searchCriteria = criteria.ToCategorySearchCriteriaDto(workContext);
            var result         = await _catalogModuleApi.CatalogModuleSearch.SearchCategoriesAsync(searchCriteria);

            var retVal = new PagedList <Category>(new List <Category>(), 1, 1);

            if (result.Items != null)
            {
                retVal = new PagedList <Category>(result.Items.Select(x => x.ToCategory(workContext.CurrentLanguage, workContext.CurrentStore)), criteria.PageNumber, criteria.PageSize);
            }

            //Set  lazy loading for child categories
            SetChildCategoriesLazyLoading(retVal.ToArray());
            return(retVal);
        }
示例#2
0
        private async Task <IPagedList <Category> > InnerSearchCategoriesAsync(CategorySearchCriteria criteria, WorkContext workContext)
        {
            var cacheKey     = CacheKey.With(GetType(), "InnerSearchCategoriesAsync", criteria.GetCacheKey(), workContext.CurrentStore.Id, workContext.CurrentLanguage.CultureName, workContext.CurrentCurrency.Code);
            var searchResult = await _memoryCache.GetOrCreateExclusiveAsync(cacheKey, async (cacheEntry) =>
            {
                cacheEntry.AddExpirationToken(CatalogCacheRegion.CreateChangeToken());
                cacheEntry.AddExpirationToken(_apiChangesWatcher.CreateChangeToken());

                criteria           = criteria.Clone();
                var searchCriteria = criteria.ToCategorySearchCriteriaDto(workContext);
                return(await _searchApi.SearchCategoriesAsync(searchCriteria));
            });

            var result = new PagedList <Category>(new List <Category>().AsQueryable(), 1, 1);

            if (searchResult.Items != null)
            {
                result = new PagedList <Category>(searchResult.Items.Select(x => x.ToCategory(workContext.CurrentLanguage, workContext.CurrentStore)).AsQueryable(), criteria.PageNumber, criteria.PageSize);
            }
            //Set  lazy loading for child categories
            SetChildCategoriesLazyLoading(result.ToArray());
            return(result);
        }
        /// <summary>
        /// Async search categories by given criteria
        /// </summary>
        /// <param name="criteria"></param>
        /// <returns></returns>
        public virtual async Task <IPagedList <Category> > SearchCategoriesAsync(CategorySearchCriteria criteria)
        {
            var workContext  = _workContextAccessor.WorkContext;
            var cacheKey     = CacheKey.With(GetType(), nameof(SearchCategoriesAsync), criteria.GetCacheKey(), workContext.CurrentStore.Id, workContext.CurrentLanguage.CultureName, workContext.CurrentCurrency.Code);
            var searchResult = await _memoryCache.GetOrCreateExclusiveAsync(cacheKey, async (cacheEntry) =>
            {
                cacheEntry.AddExpirationToken(CatalogCacheRegion.CreateChangeToken());
                cacheEntry.AddExpirationToken(_apiChangesWatcher.CreateChangeToken());

                criteria           = criteria.Clone() as CategorySearchCriteria;
                var searchCriteria = criteria.ToCategorySearchCriteriaDto(workContext);
                return(await _searchApi.SearchCategoriesAsync(searchCriteria));
            });

            var result = new PagedList <Category>(new List <Category>().AsQueryable(), 1, 1);

            if (searchResult.Items != null)
            {
                result = new PagedList <Category>(searchResult.Items.Select(x => x.ToCategory(workContext.CurrentLanguage, workContext.CurrentStore)).AsQueryable(), criteria.PageNumber, criteria.PageSize);
            }
            //Set  lazy loading for child categories
            EstablishLazyDependenciesForCategories(result.ToArray());
            return(result);
        }