public virtual async Task <GenericSearchResult <InventoryInfo> > SearchInventoriesAsync(InventorySearchCriteria criteria) { var cacheKey = CacheKey.With(GetType(), "SearchInventoriesAsync", criteria.GetCacheKey()); return(await PlatformMemoryCache.GetOrCreateExclusiveAsync(cacheKey, async (cacheEntry) => { cacheEntry.AddExpirationToken(InventorySearchCacheRegion.CreateChangeToken()); var result = new GenericSearchResult <InventoryInfo>(); using (var repository = RepositoryFactory()) { repository.DisableChangesTracking(); var sortInfos = GetSortInfos(criteria); var query = GetQuery(repository, criteria, sortInfos); result.TotalCount = await query.CountAsync(); if (criteria.Take > 0) { var inventoryIds = await query.Select(x => x.Id).Skip(criteria.Skip).Take(criteria.Take).ToArrayAsync(); result.Results = (await InventoryService.GetByIdsAsync(inventoryIds, criteria.ResponseGroup)).AsQueryable().OrderBySortInfos(sortInfos).ToArray(); } } return result; })); }
public GenericSearchResult <InventoryInfo> SearchInventories(InventorySearchCriteria criteria) { var cacheKey = GetCacheKey("IInventorySearchService.SearchInventories", criteria.GetCacheKey()); var retVal = _cacheManager.Get(cacheKey, RegionName, () => _inventorySearchService.SearchInventories(criteria)); return(retVal); }
public async Task <GenericSearchResult <InventoryInfo> > SearchInventoriesAsync(InventorySearchCriteria criteria) { var cacheKey = CacheKey.With(GetType(), "SearchInventoriesAsync", criteria.GetCacheKey()); return(await _platformMemoryCache.GetOrCreateExclusiveAsync(cacheKey, async (cacheEntry) => { var result = new GenericSearchResult <InventoryInfo>(); using (var repository = _repositoryFactory()) { repository.DisableChangesTracking(); var query = repository.Inventories; if (!criteria.ProductIds.IsNullOrEmpty()) { query = query.Where(x => criteria.ProductIds.Contains(x.Sku)); } if (!criteria.FulfillmentCenterIds.IsNullOrEmpty()) { query = query.Where(x => criteria.FulfillmentCenterIds.Contains(x.FulfillmentCenterId)); } var sortInfos = criteria.SortInfos; if (sortInfos.IsNullOrEmpty()) { sortInfos = new[] { new SortInfo { SortColumn = "ModifiedDate" } }; } query = query.OrderBySortInfos(sortInfos); result.TotalCount = await query.CountAsync(); var list = await query.Skip(criteria.Skip).Take(criteria.Take).ToArrayAsync(); result.Results = list .Select(x => { var inventory = x.ToModel(AbstractTypeFactory <InventoryInfo> .TryCreateInstance()); cacheEntry.AddExpirationToken(InventoryCacheRegion.CreateChangeToken(inventory)); return inventory; }) .ToList(); } return result; })); }