Example #1
0
        public async Task <IPagingResult <ListProductResponse> > List(IPagingCriteria criteria)
        {
            IPipelineAsync pipeline = HttpContextHelper.GetService <IPipelineAsync>();

            var builder = HttpContextHelper.GetService <IListProductBuilder>();

            builder.Builder(pipeline);

            var result = await pipeline.Execute(criteria.ToMessage());

            return(result.GetContent <IPagingResult <ListProductResponse> >());
        }
Example #2
0
        public static IQueryable <T> Page <T>(this IQueryable <T> qry, IPagingCriteria paging)
        {
            if (paging.SortParams == null)
            {
                return(qry.OrderBy(a => 1).GetPage(paging.PageParam));
            }

            if (paging.SortParams.Length == 0)
            {
                return(qry.OrderBy(a => 1).GetPage(paging.PageParam));
            }

            return(qry.OrderBy(paging.SortParams).GetPage(paging.PageParam));
        }
Example #3
0
        private async Task <IPagingResult <GetByCustomerResponse> > GetByCache(GetByCustomerRequest filter, IPagingCriteria criteria)
        {
            try
            {
                int limit  = MaxQtyByQueryPage;
                int offset = 0;

                if (criteria != null)
                {
                    limit  = criteria.Limit > 0 ? criteria.Limit : limit;
                    offset = criteria.Offset;
                }

                var repo = UnitOfWork.GetRepositoryAsync <Customer>();

                // apply filter
                Expression <Func <Customer, bool> > clause =
                    x => string.IsNullOrEmpty(filter.Name) || x.Name.Contains(filter.Name);

                // get items
                var items = await repo.GetByAsync(clause, criteria);

                // summary results
                var totalCount = await repo.GetByCountAsync(clause);

                var totalPages = (int)Math.Ceiling((double)totalCount / limit);

                var dtos = items.MapTo <IList <GetByCustomerResponse> >();

                var result = await dtos.ToBusinessPagingAsync(
                    new PageResult(limit, offset, items.Count),
                    new SummaryResult(totalCount, totalPages)
                    );

                return(result);
            }
            catch (Exception ex)
            {
                Logging.Error(ex);
                throw ex;
            }
        }
Example #4
0
        public async Task <IPagingResult <GetByCustomerResponse> > GetBy(GetByCustomerRequest filter, IPagingCriteria criteria)
        {
            #region [ Config Cache ]
            string   keyCache        = string.Format(keyGetByCache, filter.Name, criteria?.GetHashCode() ?? 0);
            TimeSpan expirationCache = TimeSpan.FromHours(1);
            #endregion

            if (!_cache.TryGetValue(keyCache, out IPagingResult <GetByCustomerResponse> result))
            {
                result = await GetByCache(filter, criteria);

                if (!result.HasErrors)
                {
                    var cacheEntryOptions = new MemoryCacheEntryOptions()
                                            .SetSlidingExpiration(expirationCache);

                    // Save data in cache.
                    _cache.Set(keyCache, result, cacheEntryOptions);
                }
            }

            return(result);
        }