Пример #1
0
            public async Task <CategorySummaryModel> Handle(GetCategorySummaryQuery request, CancellationToken cancellationToken)
            {
                categoryOverviewItems = new List <CategoryOverviewItem>();

                paymentLastTwelveMonths = await contextAdapter.Context
                                          .Payments
                                          .Include(x => x.Category)
                                          .Where(x => x.Date.Date >= DateTime.Today.AddMonths(-12))
                                          .Where(x => x.Type != PaymentType.Transfer)
                                          .ToListAsync(cancellationToken);

                List <Payment> paymentsInTimeRange = await contextAdapter.Context
                                                     .Payments
                                                     .Include(x => x.Category)
                                                     .Where(x => x.Date.Date >= request.StartDate.Date &&
                                                            x.Date.Date <= request.EndDate.Date)
                                                     .Where(x => x.Type != PaymentType.Transfer)
                                                     .ToListAsync(cancellationToken);

                foreach (Category category in paymentsInTimeRange.Where(x => x.Category != null).Select(x => x.Category !).Distinct())
                {
                    CreateOverviewItem(paymentsInTimeRange, category);
                }

                AddEntryForPaymentsWithoutCategory(paymentsInTimeRange);

                CalculatePercentage(categoryOverviewItems);
                StatisticUtilities.RoundStatisticItems(categoryOverviewItems);

                return(new CategorySummaryModel(Convert.ToDecimal(categoryOverviewItems.Where(x => x.Value > 0).Sum(x => x.Value)),
                                                Convert.ToDecimal(categoryOverviewItems.Where(x => x.Value < 0).Sum(x => x.Value)),
                                                categoryOverviewItems.Where(x => Math.Abs(x.Value) > 0.1m).OrderBy(x => x.Value).ToList()));
            }
            public async Task <CategorySummaryModel> Handle(GetCategorySummaryQuery request, CancellationToken cancellationToken)
            {
                categoryOverviewItems = new List <CategoryOverviewItem>();

                paymentLastTwelveMonths = await contextAdapter.Context
                                          .Payments
                                          .Include(x => x.Category)
                                          .Where(x => x.Date.Date >= DateTime.Today.AddMonths(NUMBERS_OF_MONTHS_TO_LOAD))
                                          .WithoutTransfers()
                                          .ToListAsync(cancellationToken);

                List <Payment> paymentsInTimeRange = await contextAdapter.Context
                                                     .Payments
                                                     .Include(x => x.Category)
                                                     .HasDateLargerEqualsThan(request.StartDate.Date)
                                                     .HasDateSmallerEqualsThan(request.EndDate.Date)
                                                     .Where(x => x.Type != PaymentType.Transfer)
                                                     .ToListAsync(cancellationToken);

                foreach (Category category in paymentsInTimeRange.Where(x => x.Category != null).Select(x => x.Category !).Distinct())
                {
                    CreateOverviewItem(paymentsInTimeRange, category);
                }

                AddEntryForPaymentsWithoutCategory(paymentsInTimeRange);

                CalculatePercentage(categoryOverviewItems);
                StatisticUtilities.RoundStatisticItems(categoryOverviewItems);

                return(new CategorySummaryModel(Convert.ToDecimal(paymentsInTimeRange.Where(x => x.Type == PaymentType.Income).Sum(x => x.Amount)),
                                                Convert.ToDecimal(paymentsInTimeRange.Where(x => x.Type == PaymentType.Expense).Sum(x => x.Amount)),
                                                categoryOverviewItems.Where(x => Math.Abs(x.Value) > DECIMAL_DELTA).OrderBy(x => x.Value).ToList()));
            }