Esempio n. 1
0
        public virtual async Task <GenericSearchResult <FulfillmentCenter> > SearchCentersAsync(FulfillmentCenterSearchCriteria criteria)
        {
            var cacheKey = CacheKey.With(GetType(), "SearchCentersAsync", criteria.GetCacheKey());

            return(await PlatformMemoryCache.GetOrCreateExclusiveAsync(cacheKey, async (cacheEntry) =>
            {
                cacheEntry.AddExpirationToken(FulfillmentCenterCacheRegion.CreateChangeToken());
                var result = new GenericSearchResult <FulfillmentCenter>();
                using (var repository = RepositoryFactory())
                {
                    repository.DisableChangesTracking();

                    var sortInfos = GetSortInfos(criteria);
                    var query = GetFulfillmentCenterQuery(repository, criteria, sortInfos);

                    result.TotalCount = await query.CountAsync();

                    var fulfillmentCenterEntities = new FulfillmentCenterEntity[0];
                    if (criteria.Take > 0)
                    {
                        fulfillmentCenterEntities = await query.Skip(criteria.Skip).Take(criteria.Take).ToArrayAsync();
                    }

                    result.Results = fulfillmentCenterEntities
                                     .Select(x => x.ToModel(AbstractTypeFactory <FulfillmentCenter> .TryCreateInstance()))
                                     .ToList();
                }
                return result;
            }));
        }
Esempio n. 2
0
        public async Task <IEnumerable <FulfillmentCenter> > GetByIdsAsync(IEnumerable <string> ids)
        {
            if (ids == null)
            {
                throw new ArgumentNullException(nameof(ids));
            }
            var cacheKey = CacheKey.With(GetType(), "GetByIdsAsync", string.Join("-", ids.OrderBy(x => x)));

            return(await _platformMemoryCache.GetOrCreateExclusiveAsync(cacheKey, async (cacheEntry) =>
            {
                cacheEntry.AddExpirationToken(FulfillmentCenterCacheRegion.CreateChangeToken());
                IEnumerable <FulfillmentCenter> result = null;
                using (var repository = _repositoryFactory())
                {
                    repository.DisableChangesTracking();

                    var fulfillmentCenters = await repository.GetFulfillmentCentersAsync(ids);
                    result = fulfillmentCenters
                             .Select(x => x.ToModel(AbstractTypeFactory <FulfillmentCenter> .TryCreateInstance())).ToArray();
                }
                return result;
            }));
        }
Esempio n. 3
0
        public async Task <GenericSearchResult <FulfillmentCenter> > SearchCentersAsync(FulfillmentCenterSearchCriteria criteria)
        {
            var cacheKey = CacheKey.With(GetType(), "SearchCentersAsync", criteria.GetCacheKey());

            return(await _platformMemoryCache.GetOrCreateExclusiveAsync(cacheKey, async (cacheEntry) =>
            {
                cacheEntry.AddExpirationToken(FulfillmentCenterCacheRegion.CreateChangeToken());
                var result = new GenericSearchResult <FulfillmentCenter>();
                using (var repository = _repositoryFactory())
                {
                    repository.DisableChangesTracking();

                    var query = repository.FulfillmentCenters;
                    if (!string.IsNullOrEmpty(criteria.Keyword))
                    {
                        query = query.Where(x => x.Name.Contains(criteria.Keyword));
                    }

                    var sortInfos = criteria.SortInfos;
                    if (sortInfos.IsNullOrEmpty())
                    {
                        sortInfos = new[] { new SortInfo {
                                                SortColumn = "Name"
                                            } };
                    }

                    query = query.OrderBySortInfos(sortInfos);

                    result.TotalCount = await query.CountAsync();
                    var arrayFullfillmentCenters = await query.Skip(criteria.Skip).Take(criteria.Take).ToArrayAsync();
                    result.Results = arrayFullfillmentCenters
                                     .Select(x => x.ToModel(AbstractTypeFactory <FulfillmentCenter> .TryCreateInstance()))
                                     .ToList();
                }
                return result;
            }));
        }