Ejemplo n.º 1
0
        public async Task <IPagingResult <GetByCustomerResponse> > GetBy([FromQuery] GetByCustomerRequest filter, [FromQuery] PagingCriteriaRequest clause)
        {
            var result = await FacadeService.CustomerService.GetBy(filter, clause.ToPagingService());

            result.AddLinkSelf("CustomerGetBy");
            result.AddLinkItem("CustomerGetById");
            return(result);
        }
Ejemplo n.º 2
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;
            }
        }
Ejemplo n.º 3
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);
        }