public virtual async Task <PaymentSearchResult> SearchPaymentsAsync(PaymentSearchCriteria criteria)
        {
            var cacheKey = CacheKey.With(GetType(), nameof(PaymentSearchCriteria), criteria.GetCacheKey());

            return(await _platformMemoryCache.GetOrCreateExclusiveAsync(cacheKey, async (cacheEntry) =>
            {
                cacheEntry.AddExpirationToken(OrderSearchCacheRegion.CreateChangeToken());
                using (var repository = _repositoryFactory())
                {
                    repository.DisableChangesTracking();

                    var result = AbstractTypeFactory <PaymentSearchResult> .TryCreateInstance();

                    var query = BuildQuery(repository, criteria);
                    var sortInfos = BuildSortExpression(criteria);

                    result.TotalCount = await query.CountAsync();
                    if (criteria.Take > 0)
                    {
                        var ids = await query.OrderBySortInfos(sortInfos).ThenBy(x => x.Id)
                                  .Select(x => x.Id)
                                  .Skip(criteria.Skip).Take(criteria.Take)
                                  .ToArrayAsync();
                        var unorderedResults = await _paymentService.GetByIdsAsync(ids, criteria.ResponseGroup);
                        result.Results = unorderedResults.OrderBy(x => Array.IndexOf(ids, x.Id)).ToList();
                    }
                    return result;
                }
            }));
        }
        public async Task <ActionResult <DashboardStatisticsResult> > GetDashboardStatisticsAsync([FromQuery] DateTime?start = null, [FromQuery] DateTime?end = null)
        {
            start ??= DateTime.UtcNow.AddYears(-1);
            end ??= DateTime.UtcNow;

            // Hack: to compinsate for incorrect Local dates to UTC
            end = end.Value.AddDays(2);
            var cacheKey = CacheKey.With(GetType(), string.Join(":", "Statistic", start.Value.ToString("yyyy-MM-dd"), end.Value.ToString("yyyy-MM-dd")));
            var retVal   = await _platformMemoryCache.GetOrCreateExclusiveAsync(cacheKey, async (cacheEntry) =>
            {
                cacheEntry.AddExpirationToken(OrderSearchCacheRegion.CreateChangeToken());
                var collectStaticJob = new CollectOrderStatisticJob(_repositoryFactory);
                var result           = await collectStaticJob.CollectStatisticsAsync(start.Value, end.Value);
                return(result);
            });

            return(Ok(retVal));
        }
예제 #3
0
        public virtual async Task <GenericSearchResult <CustomerOrder> > SearchCustomerOrdersAsync(CustomerOrderSearchCriteria criteria)
        {
            var cacheKey = CacheKey.With(GetType(), "SearchCustomerOrdersAsync", criteria.GetCacheKey());

            return(await _platformMemoryCache.GetOrCreateExclusiveAsync(cacheKey, async (cacheEntry) =>
            {
                cacheEntry.AddExpirationToken(OrderSearchCacheRegion.CreateChangeToken());
                using (var repository = _repositoryFactory())
                {
                    repository.DisableChangesTracking();
                    var retVal = new GenericSearchResult <CustomerOrder>();
                    var orderResponseGroup = EnumUtility.SafeParse(criteria.ResponseGroup, CustomerOrderResponseGroup.Full);

                    var query = GetOrdersQuery(repository, criteria);

                    var sortInfos = criteria.SortInfos;
                    if (sortInfos.IsNullOrEmpty())
                    {
                        sortInfos = new[]
                        {
                            new SortInfo
                            {
                                SortColumn = ReflectionUtility.GetPropertyName <CustomerOrderEntity>(x => x.CreatedDate),
                                SortDirection = SortDirection.Descending
                            }
                        };
                    }
                    query = query.OrderBySortInfos(sortInfos);

                    retVal.TotalCount = await query.CountAsync();
                    var orderIds = await query.Select(x => x.Id).Skip(criteria.Skip).Take(criteria.Take).ToArrayAsync();

                    var list = await repository.GetCustomerOrdersByIdsAsync(orderIds, orderResponseGroup);

                    retVal.Results = list.Select(x =>
                                                 x.ToModel(AbstractTypeFactory <CustomerOrder> .TryCreateInstance()) as CustomerOrder).ToList();

                    return retVal;
                }
            }));
        }