コード例 #1
0
ファイル: IncomesQueries.cs プロジェクト: lulzzz/Monifier
        public async Task <IncomesListModel> GetIncomesByMonth(DateTime dateFrom, DateTime dateTo,
                                                               PaginationArgs paginationArgs)
        {
            dateFrom = dateFrom.StartOfTheMonth();
            dateTo   = dateTo.EndOfTheMonth();

            var incomesQueries = _repository.GetQuery <IncomeItem>();
            var typesQueries   = _repository.GetQuery <IncomeType>();
            var ownerId        = _currentSession.UserId;

            var incomesQuery =
                from income in incomesQueries
                join itype in typesQueries on income.IncomeTypeId equals itype.Id
                where income.OwnerId == ownerId && income.DateTime >= dateFrom && income.DateTime < dateTo
                orderby income.Total descending
                group new { income, itype } by new { income.DateTime.Year, income.DateTime.Month }
            into incomeGroups
                select new IncomeGroup
            {
                ItemIds = incomeGroups.Select(x => x.income.Id).ToList(),
                Sum     = incomeGroups.Sum(x => x.income.Total),
                Types   = incomeGroups.Select(x => x.itype.Name).Distinct().ToList(),
                Month   = new DateTime(incomeGroups.Key.Year, incomeGroups.Key.Month, 1)
            };

            var incomesCount = await incomesQuery.CountAsync().ConfigureAwait(false);

            var pagination = new PaginationInfo(paginationArgs, incomesCount);

            var incomes = await incomesQuery
                          .Skip(pagination.Skipped)
                          .Take(pagination.Taken)
                          .ToListAsync()
                          .ConfigureAwait(false);

            var totals = await incomesQueries
                         .Where(x => x.OwnerId == ownerId && x.DateTime >= dateFrom && x.DateTime < dateTo)
                         .SumAsync(x => x.Total)
                         .ConfigureAwait(false);

            return(new IncomesListModel
            {
                Incomes = incomes.Select(x => new IncomesListItemModel
                {
                    ItemIds = x.ItemIds,
                    Caption = x.Month.GetMonthName(),
                    DateFrom = x.Month.ToStandardString(),
                    DateTo = x.Month.EndOfTheMonth().ToStandardString(),
                    Interval = $"{x.Month.ToStandardDateStr()} - {x.Month.EndOfTheMonth().ToStandardDateStr()}",
                    Sum = x.Sum,
                    Types = x.Types.GetLaconicString()
                }).ToList(),
                Pagination = pagination,
                Totals = new TotalsInfoModel
                {
                    Caption = $"Итого доход за период с {dateFrom.ToStandardDateStr()} по {dateTo.ToStandardDateStr()}",
                    Total = totals
                }
            });
        }
コード例 #2
0
ファイル: ExpenseFlowQueries.cs プロジェクト: lulzzz/Monifier
        public async Task <ExpenseFlowList> GetList(PaginationArgs args)
        {
            var flowQueries = _repository.GetQuery <ExpenseFlow>();
            var ownerId     = _currentSession.UserId;
            var query       = flowQueries
                              .Where(x => (!x.IsDeleted || args.IncludeDeleted) && x.OwnerId == ownerId)
                              .OrderByDescending(x => x.Version)
                              .ThenBy(x => x.Id);

            var totalCount = await query.CountAsync();

            var pagination = new PaginationInfo(args, totalCount);
            var flows      = await query
                             .Skip(pagination.Skipped)
                             .Take(pagination.Taken)
                             .Select(x => x.ToModel())
                             .ToListAsync()
                             .ConfigureAwait(false);

            var total = await query.Select(x => x.Balance).SumAsync().ConfigureAwait(false);

            return(new ExpenseFlowList
            {
                ExpenseFlows = flows,
                Totals = new TotalsInfoModel
                {
                    Caption = "Всего на балансе:",
                    Total = total
                },
                Pagination = pagination
            });
        }
コード例 #3
0
        public async Task <CategoryList> GetList(PaginationArgs args)
        {
            var ownerId = _currentSession.UserId;
            var query   = args.IncludeDeleted
                ? _repository.GetQuery <Category>()
                : _repository.GetQuery <Category>().Where(x => !x.IsDeleted);

            query = query.Where(x => x.OwnerId == ownerId);
            var totalCount = await query.CountAsync();

            var pagination = new PaginationInfo(args, totalCount);
            var models     = await query
                             .OrderBy(x => x.Id)
                             .Skip(pagination.Skipped).Take(pagination.Taken)
                             .Select(x => new CategoryModel
            {
                Id           = x.Id,
                Name         = x.Name,
                ProductCount = x.Products.Count
            }
                                     )
                             .ToListAsync()
                             .ConfigureAwait(false);

            return(new CategoryList
            {
                List = models,
                Pagination = pagination
            });
        }
コード例 #4
0
ファイル: ExpensesQueries.cs プロジェクト: lulzzz/Monifier
        private async Task <BillGoodsGroupWithPagination> GetGoodsGroupsByDayAsync(
            int?flowId, DateTime dateFrom, DateTime dateTo, PaginationArgs paginationArgs)
        {
            var expenseQueries  = _repository.GetQuery <ExpenseBill>();
            var ownerId         = _currentSession.UserId;
            var goodsGroupQuery = expenseQueries
                                  .Where(x => x.OwnerId == ownerId && (flowId == null || x.ExpenseFlowId == flowId) &&
                                         x.DateTime >= dateFrom && x.DateTime < dateTo)
                                  .OrderBy(x => x.DateTime)
                                  .GroupBy(x => x.DateTime.Date)
                                  .Select(x => new BillGoodsGroup
            {
                BillIds  = x.Select(v => v.Id).ToList(),
                Sum      = x.Sum(v => v.SumPrice),
                DateTime = x.Key
            });

            var totalCount = await goodsGroupQuery.CountAsync();

            var pagination  = new PaginationInfo(paginationArgs, totalCount);
            var goodsGroups = await goodsGroupQuery
                              .Skip(pagination.Skipped).Take(pagination.Taken)
                              .ToListAsync()
                              .ConfigureAwait(false);

            return(new BillGoodsGroupWithPagination
            {
                GoodsGrops = goodsGroups,
                Pagination = pagination
            });
        }
コード例 #5
0
ファイル: ExpensesQueries.cs プロジェクト: lulzzz/Monifier
        private async Task <ExpensesListModel> GetExpenses(
            ExpensesFilter filter, PaginationArgs paginationArgs, bool byMonth)
        {
            var flowId   = filter.FlowId;
            var dateFrom = filter.DateFrom;
            var dateTo   = filter.DateTo;
            var userId   = _currentSession.UserId;

            // отбираем нужные счета и группируем их по дате
            var goodsGroupsWithPagination = byMonth
                ? await GetGoodsGroupsByMonthAsync(flowId, dateFrom, dateTo, paginationArgs)
                : await GetGoodsGroupsByDayAsync(flowId, dateFrom, dateTo, paginationArgs);

            var goodsGroups = goodsGroupsWithPagination.GoodsGrops;

            // группируем все товары и категории и сортируем их в порядке уменьшения общей стоимости в каждой группе
            await GroupAndSortBillsGoodsAsync(goodsGroups);

            // финальное преобразование из внутренних моделей
            var expenses = new ExpensesListModel
            {
                Expenses = goodsGroups.Select(x => new ExpensesListItemModel
                {
                    BillIds = x.BillIds,
                    Sum     = x.Sum,

                    DateFrom = byMonth
                        ? x.DateTime.StartOfTheMonth().ToStandardString()
                        : x.DateTime.Date.ToStandardString(),

                    DateTo = byMonth
                        ? x.DateTime.EndOfTheMonth().ToStandardString()
                        : x.DateTime.Date.AddDays(1).AddMinutes(-1).ToStandardString(),

                    Period = byMonth
                        ? $"{x.DateTime.StartOfTheMonth().ToStandardDateStr()} - {x.DateTime.EndOfTheMonth().ToStandardDateStr()}"
                        : x.DateTime.ToStandardDateStr(),

                    Caption         = byMonth ? x.DateTime.GetMonthName() : x.DateTime.GetWeekDayName().Capitalize(),
                    Goods           = x.Goods.Select(g => g.Name).ToList().GetLaconicString(),
                    IsDangerExpense = x.Sum >= _userSettings.DangerExpense(byMonth)
                }).ToList(),
                Pagination = goodsGroupsWithPagination.Pagination,

                // считаем тоталы
                Totals = new TotalsInfoModel
                {
                    Caption = $"Итого за период с {dateFrom.ToStandardDateStr()} по {dateTo.ToStandardDateStr()}",
                    Total   = await _repository.GetQuery <ExpenseBill>()
                              .Where(x => x.OwnerId == userId && (flowId == null || x.ExpenseFlowId == flowId) &&
                                     x.DateTime >= dateFrom && x.DateTime < dateTo)
                              .SumAsync(x => x.SumPrice)
                              .ConfigureAwait(false)
                }
            };

            return(expenses);
        }
コード例 #6
0
        public PagedResult <UserListDTO> Filter(PaginationArgs args, UserListDTOSpec spec)
        {
            var us = new List <UserListDTO>()
            {
                new UserListDTO()
                {
                    Id = 1, Name = "Zeeshan", Surname = "Zahoor"
                },
                new UserListDTO()
                {
                    Id = 2, Name = "Zeeshan", Surname = "Zahoor"
                },
                new UserListDTO()
                {
                    Id = 3, Name = "Zeeshan", Surname = "Zahoor"
                },
                new UserListDTO()
                {
                    Id = 4, Name = "Zeeshan", Surname = "Zahoor"
                },
                new UserListDTO()
                {
                    Id = 5, Name = "Zeeshan", Surname = "Zahoor"
                },
                new UserListDTO()
                {
                    Id = 6, Name = "Zeeshan", Surname = "Zahoor"
                },
                new UserListDTO()
                {
                    Id = 7, Name = "Zeeshan", Surname = "Zahoor"
                },
                new UserListDTO()
                {
                    Id = 8, Name = "Zeeshan", Surname = "Zahoor"
                },
                new UserListDTO()
                {
                    Id = 9, Name = "Zeeshan", Surname = "Zahoor"
                },
                new UserListDTO()
                {
                    Id = 10, Name = "Zeeshan", Surname = "Zahoor"
                },
                new UserListDTO()
                {
                    Id = 11, Name = "Zeeshan", Surname = "Zahoor"
                },
            };

            //var q = _userRepository.All.Select(m => new UserListDTO()
            //{

            //});
            var u = spec.ApplySpec(us.AsQueryable());

            return(this.ApplyPagination(us.AsQueryable(), args));
        }
コード例 #7
0
ファイル: BaseService.cs プロジェクト: zeeshanzahoor/Roka
        public PagedResult <T> ApplyPagination <T>(IQueryable <T> c, PaginationArgs args)
        {
            PagedResult <T> result = new PagedResult <T>()
            {
                Total = c.Count(),
                Data  = c.Skip(args.CurrentPage * args.PageSize).Take(args.PageSize).ToList(),
            };

            return(result);
        }
コード例 #8
0
        public void FromArgs_FirstPage10TotalItems_ReturnsRightTotalPagesCount()
        {
            var args = new PaginationArgs
            {
                PageNumber     = 1,
                ItemsPerPage   = 5,
                IncludeDeleted = false
            };
            var info = new PaginationInfo(args, 10);

            info.PageNumber.ShouldBeEquivalentTo(1);
            info.ItemsPerPage.ShouldBeEquivalentTo(5);
            info.TotalPageCount.ShouldBeEquivalentTo(2);
            info.Skipped.ShouldBeEquivalentTo(0);
            info.Taken.ShouldBeEquivalentTo(5);
        }
コード例 #9
0
        public async Task <FlightListDto> GetAllFlights(PaginationArgs pagination)
        {
            var flights = await _flightsRepository.GetAllAsync();

            var flightsDto = _mapper.MapFromFlights(flights.ToList()
                                                    .OrderByDescending(e => e.CreationDate)
                                                    .Skip(pagination.StartIndex.Value)
                                                    .Take(pagination.PageSize.Value));

            int total = _flightsRepository.GetTotal();

            return(new FlightListDto
            {
                Items = flightsDto,
                Total = total
            });
        }
コード例 #10
0
        // GET api/Games
        public IEnumerable <GameDTO> GetGames([FromUri] FilterArgs filters, [FromUri] PaginationArgs paginations)
        {
            if (filters == null)
            {
                filters = new FilterArgs();
            }
            if (paginations == null)
            {
                paginations = new PaginationArgs();
            }
            var games = _gameService.Get(filters, CurrentLangCode);

            paginations.TotalItems = games.Count();
            paginations.TotalPages = (paginations.TotalItems / paginations.CountPerPage) + 1;
            games = games.Skip((paginations.PageNumber - 1) * paginations.CountPerPage).Take(paginations.CountPerPage);
            return(Mapper.Map <IEnumerable <GameDTO> >(games));
        }
コード例 #11
0
        public async Task <ProductList> GetList(int categoryId, PaginationArgs args)
        {
            var query = _repository.GetQuery <Product>().Where(x => !x.IsDeleted)
                        .Where(x => x.CategoryId == categoryId);
            var totalCount = await query.CountAsync();

            var pagination = new PaginationInfo(args, totalCount);
            var models     = await query
                             .OrderBy(x => x.Id)
                             .Skip(pagination.Skipped).Take(pagination.Taken)
                             .Select(x => ToModel(x))
                             .ToListAsync()
                             .ConfigureAwait(false);

            return(new ProductList
            {
                Products = models,
                Pagination = pagination
            });
        }
コード例 #12
0
ファイル: ExpensesQueries.cs プロジェクト: lulzzz/Monifier
 public Task <ExpensesListModel> GetExpensesByDays(ExpensesFilter filter, PaginationArgs paginationArgs)
 {
     return(GetExpenses(filter, paginationArgs, false));
 }
コード例 #13
0
        public async Task <IEnumerable <AircraftDto> > GetAllAircrafts(PaginationArgs pagination)
        {
            var aircrafts = await _aircraftsRepository.GetAllAsync();

            return(_autoMapper.Map <IEnumerable <AircraftDto> >(aircrafts.ToList().Skip(pagination.StartIndex.Value).Take(pagination.PageSize.Value)));
        }
コード例 #14
0
        public IActionResult FillUserGrid([FromBody]PaginationArgs args, UserListDTOSpec spec)
        {
            var result = _userService.Filter(args, spec);

            return Json(result);
        }
コード例 #15
0
ファイル: ExpensesQueries.cs プロジェクト: lulzzz/Monifier
 public Task <ExpensesListModel> GetExpensesByMonth(ExpensesFilter filter, PaginationArgs paginationArgs)
 {
     filter.DateFrom = filter.DateFrom.StartOfTheMonth();
     filter.DateTo   = filter.DateTo.EndOfTheMonth();
     return(GetExpenses(filter, paginationArgs, true));
 }
コード例 #16
0
ファイル: ExpensesQueries.cs プロジェクト: lulzzz/Monifier
        public async Task <ExpensesByFlowsModel> GetExpensesByFlows(DateTime dateFrom, DateTime dateTo, PaginationArgs paginationArgs)
        {
            // отбираем нужные счета
            var expensesQueries = _repository.GetQuery <ExpenseBill>();

            var ownerId = _currentSession.UserId;

            var billByFlowsQuery = expensesQueries
                                   .Where(x => x.OwnerId == ownerId && x.DateTime >= dateFrom && x.DateTime < dateTo)
                                   .GroupBy(x => x.ExpenseFlowId)
                                   .Select(x => new ExpenseByFlowsItemModel
            {
                FlowId          = x.Key,
                Total           = x.Sum(e => e.SumPrice),
                Flow            = x.First().ExpenseFlow.Name,
                LastBill        = x.Max(e => e.DateTime),
                IsDangerExpense = false
            })
                                   .OrderByDescending(x => x.Total);

            var totalCount = await billByFlowsQuery.CountAsync().ConfigureAwait(false);

            var pagination = new PaginationInfo(paginationArgs, totalCount);

            // финальное преобразование из внутренних моделей
            var expenses = new ExpensesByFlowsModel
            {
                Items = await billByFlowsQuery
                        .Skip(pagination.Skipped)
                        .Take(pagination.Taken)
                        .ToListAsync()
                        .ConfigureAwait(false),

                // считаем тоталы
                Totals = new TotalsInfoModel
                {
                    Caption = $"Итого за период с {dateFrom.ToStandardString()} по {dateTo.ToStandardString()}",
                    Total   = await expensesQueries
                              .Where(x => x.OwnerId == ownerId && x.DateTime >= dateFrom && x.DateTime < dateTo)
                              .SumAsync(x => x.SumPrice)
                              .ConfigureAwait(false)
                },

                Pagination = pagination
            };

            return(expenses);
        }
コード例 #17
0
 public SearchAircraftsArgs()
 {
     Pagination = new PaginationArgs();
 }
コード例 #18
0
 public SearchAirportsArgs()
 {
     Pagination = new PaginationArgs();
 }
コード例 #19
0
        public async void GetAllTransactions_MainTest()
        {
            using (var session = await CreateSession(UserEvgeny))
            {
                var ids             = session.CreateDefaultEntities();
                var accountCommands = session.CreateAccountCommands();
                await accountCommands.Transfer(ids.DebitCardAccountId, ids.CashAccountId, 1000);

                await accountCommands.Transfer(ids.CashAccountId, ids.DebitCardAccountId, 2000);

                var incomeCommands = session.CreateIncomeCommands();
                await incomeCommands.Update(new IncomeItemModel
                {
                    AccountId    = ids.DebitCardAccountId,
                    DateTime     = DateTime.UtcNow,
                    Total        = 1450,
                    IncomeTypeId = ids.GiftsIncomeId,
                });

                await session.CreateExpenseBill(ids.DebitCardAccountId, ids.FoodExpenseFlowId,
                                                DateTime.Now, session.Meat, 350);

                await session.CreateExpenseBill(ids.CashAccountId, ids.TechExpenseFlowId,
                                                DateTime.Now, session.Tv, 15000);

                await session.CreateExpenseBill(ids.DebitCardAccountId, ids.TechExpenseFlowId,
                                                DateTime.Now, session.Tv, 5600);
            }

            using (var session = await CreateDefaultSession())
            {
                var ids               = session.CreateDefaultEntities();
                var accountCommands   = session.CreateAccountCommands();
                var transfer1DateTime = await accountCommands.Transfer(ids.DebitCardAccountId, ids.CashAccountId, 1000);

                var transfer2DateTime = await accountCommands.Transfer(ids.CashAccountId, ids.DebitCardAccountId, 2000);

                var incomeCommands = session.CreateIncomeCommands();
                var income         = await incomeCommands.Update(new IncomeItemModel
                {
                    AccountId    = ids.DebitCardAccountId,
                    DateTime     = DateTime.UtcNow,
                    Total        = 1450,
                    IncomeTypeId = ids.GiftsIncomeId,
                });

                var oldIncome = await incomeCommands.Update(new IncomeItemModel
                {
                    AccountId    = ids.DebitCardAccountId,
                    DateTime     = DateTime.UtcNow.AddDays(-100),
                    Total        = 3456,
                    IncomeTypeId = ids.SalaryIncomeId,
                });

                var veryOldIncome = await incomeCommands.Update(new IncomeItemModel
                {
                    AccountId    = ids.DebitCardAccountId,
                    DateTime     = DateTime.UtcNow.AddDays(-1000),
                    Total        = 6478,
                    IncomeTypeId = ids.GiftsIncomeId,
                });

                var bill1 = await session.CreateExpenseBill(ids.DebitCardAccountId, ids.FoodExpenseFlowId,
                                                            DateTime.Now, session.Meat, 350);

                var bill2 = await session.CreateExpenseBill(ids.CashAccountId, ids.TechExpenseFlowId,
                                                            DateTime.Now, session.Tv, 15000);

                var bill3 = await session.CreateExpenseBill(ids.DebitCardAccountId, ids.TechExpenseFlowId,
                                                            DateTime.Now, session.Tv, 5600);

                var oldBill = await session.CreateExpenseBill(ids.DebitCardAccountId, ids.FoodExpenseFlowId,
                                                              DateTime.UtcNow.AddDays(-1010), session.Bread, 200);

                var veryOldBill = await session.CreateExpenseBill(ids.CashAccountId, ids.FoodExpenseFlowId,
                                                                  DateTime.UtcNow.AddDays(-500), session.Bread, 333);

                var transationsQueries = session.CreateTransactionQueries();
                var paginationArgs     = new PaginationArgs
                {
                    PageNumber     = 1,
                    ItemsPerPage   = int.MaxValue,
                    IncludeDeleted = true
                };
                var transactionsPaged = await transationsQueries.GetAllTransactions(new TransactionFilter { AccountId = ids.DebitCardAccountId }, paginationArgs);

                transactionsPaged.Transactions.ShouldBeEquivalentTo(new[]
                {
                    new TransactionViewModel
                    {
                        IsExpense = true,
                        DateTime  = bill3.DateTime,
                        Type      = "Оплата",
                        Target    = session.TechExpenseFlow.Name,
                        Total     = ToMoney(-5600),
                        Balance   = ToMoney(21434, false)
                    },
                    new TransactionViewModel
                    {
                        IsExpense = true,
                        DateTime  = bill1.DateTime,
                        Type      = "Оплата",
                        Target    = session.FoodExpenseFlow.Name,
                        Total     = ToMoney(-350),
                        Balance   = ToMoney(27034, false)
                    },
                    new TransactionViewModel
                    {
                        IsExpense = false,
                        DateTime  = income.DateTime,
                        Type      = "Поступление",
                        Target    = session.GiftsIncome.Name,
                        Total     = ToMoney(1450),
                        Balance   = ToMoney(17450, false)
                    },
                    new TransactionViewModel
                    {
                        IsExpense = false,
                        DateTime  = transfer2DateTime,
                        Type      = "Перевод",
                        Target    = session.CashAccount.Name,
                        Total     = ToMoney(2000),
                        Balance   = ToMoney(16000, false)
                    },
                    new TransactionViewModel
                    {
                        IsExpense = true,
                        DateTime  = transfer1DateTime,
                        Type      = "Перевод",
                        Target    = session.CashAccount.Name,
                        Total     = ToMoney(-1000),
                        Balance   = ToMoney(14000, false)
                    },
                    new TransactionViewModel
                    {
                        IsExpense = false,
                        DateTime  = oldIncome.DateTime,
                        Type      = "Поступление",
                        Target    = session.SalaryIncome.Name,
                        Total     = ToMoney(3456),
                        Balance   = ToMoney(20906, false)
                    },
                    new TransactionViewModel
                    {
                        IsExpense = false,
                        DateTime  = veryOldIncome.DateTime,
                        Type      = "Поступление",
                        Target    = session.GiftsIncome.Name,
                        Total     = ToMoney(6478),
                        Balance   = ToMoney(27384, false)
                    },
                    new TransactionViewModel
                    {
                        IsExpense = true,
                        DateTime  = oldBill.DateTime,
                        Type      = "Оплата",
                        Target    = session.FoodExpenseFlow.Name,
                        Total     = ToMoney(-200),
                        Balance   = ToMoney(21234, false)
                    },
                });

                var last = await transationsQueries.GetLastTransactions(ids.CashAccountId);

                last.ShouldBeEquivalentTo(new[]
                {
                    new TransactionViewModel
                    {
                        IsExpense = true,
                        DateTime  = bill2.DateTime,
                        Type      = "Оплата",
                        Target    = session.TechExpenseFlow.Name,
                        Total     = ToMoney(-15000),
                        Balance   = ToMoney(14000, false)
                    },
                    new TransactionViewModel
                    {
                        IsExpense = true,
                        DateTime  = transfer2DateTime,
                        Type      = "Перевод",
                        Target    = session.DebitCardAccount.Name,
                        Total     = ToMoney(-2000),
                        Balance   = ToMoney(29000, false)
                    },
                    new TransactionViewModel
                    {
                        IsExpense = false,
                        DateTime  = transfer1DateTime,
                        Type      = "Перевод",
                        Target    = session.DebitCardAccount.Name,
                        Total     = ToMoney(1000),
                        Balance   = ToMoney(31000, false)
                    },
                    new TransactionViewModel
                    {
                        IsExpense = true,
                        DateTime  = veryOldBill.DateTime,
                        Type      = "Оплата",
                        Target    = session.FoodExpenseFlow.Name,
                        Total     = ToMoney(-333),
                        Balance   = ToMoney(13667, false)
                    },
                }
                                          );
            }
        }
コード例 #20
0
 public SearchFlightsArgs()
 {
     Pagination = new PaginationArgs();
 }
コード例 #21
0
ファイル: IncomesQueries.cs プロジェクト: lulzzz/Monifier
        public async Task <IncomesListModel> GetIncomesList(DateTime dateFrom, DateTime dateTo,
                                                            PaginationArgs paginationArgs)
        {
            var incomesQueries = _repository.GetQuery <IncomeItem>();
            var typeQueries    = _repository.GetQuery <IncomeType>();
            var accountQueries = _repository.GetQuery <Account>();
            var ownerId        = _currentSession.UserId;

            var incomesQuery =
                from income in incomesQueries
                join itype in typeQueries on income.IncomeTypeId equals itype.Id
                join account in accountQueries on income.AccountId equals account.Id
                where income.OwnerId == ownerId && income.DateTime >= dateFrom && income.DateTime < dateTo
                orderby income.DateTime
                select new
            {
                Income     = income,
                IncomeType = itype.Name,
                Account    = account.Name
            };

            var incomesCount = await incomesQuery.CountAsync().ConfigureAwait(false);

            var pagination = new PaginationInfo(paginationArgs, incomesCount);

            var incomes = await incomesQuery
                          .Skip(pagination.Skipped)
                          .Take(pagination.Taken)
                          .ToListAsync()
                          .ConfigureAwait(false);

            var totals = await incomesQueries
                         .Where(x => x.OwnerId == ownerId && x.DateTime >= dateFrom && x.DateTime < dateTo)
                         .SumAsync(x => x.Total)
                         .ConfigureAwait(false);

            var result = new IncomesListModel
            {
                Incomes    = new List <IncomesListItemModel>(),
                Pagination = pagination,
                Totals     = new TotalsInfoModel
                {
                    Caption = $"Итого доход за период с {dateFrom.ToStandardString()} по {dateTo.ToStandardString()}",
                    Total   = totals
                }
            };

            foreach (var item in incomes)
            {
                var strDateTime = item.Income.DateTime.ToStandardString();
                result.Incomes.Add(new IncomesListItemModel
                {
                    ItemIds = new List <int> {
                        item.Income.Id
                    },
                    Caption  = item.Account,
                    DateFrom = strDateTime,
                    DateTo   = strDateTime,
                    Interval = strDateTime,
                    Sum      = item.Income.Total,
                    Types    = item.IncomeType
                });
            }

            return(result);
        }
コード例 #22
0
ファイル: TransactionQueries.cs プロジェクト: lulzzz/Monifier
        public async Task <TransactionPaginatedList> GetAllTransactions(TransactionFilter filter, PaginationArgs paginationArgs)
        {
            var initiatorId = filter.AccountId;
            var queries     = _repository.GetQuery <Transaction>();
            var ownerId     = _currentSession.UserId;
            var itemsQuery  = queries
                              .Where(x => x.OwnerId == ownerId && x.InitiatorId == initiatorId && !x.IsDeleted)
                              .OrderByDescending(x => x.DateTime)
                              .Select(x => new
            {
                x.DateTime,
                Total       = GetTransactionTotal(x),
                Type        = GetTransactionViewType(x),
                Transaction = x,
            })
                              .Where(x => string.IsNullOrEmpty(filter.Operation) || x.Type == filter.Operation);

            var pagination = new PaginationInfo(paginationArgs, await itemsQuery.CountAsync().ConfigureAwait(false));

            var items = await itemsQuery
                        .Skip(pagination.Skipped)
                        .Take(pagination.Taken)
                        .ToListAsync()
                        .ConfigureAwait(false);

            var list = new List <TransactionViewModel>();

            foreach (var item in items)
            {
                var model = new TransactionViewModel
                {
                    IsExpense = item.Total < 0,
                    DateTime  = item.DateTime,
                    Total     = item.Total > 0 ? $"+{item.Total.ToMoney()}" : item.Total.ToMoney(),
                    Type      = item.Type,
                    Target    = await GetTransactionTarget(item.Transaction),
                    Balance   = item.Transaction.Balance?.ToMoney()
                };
                list.Add(model);
            }

            return(new TransactionPaginatedList
            {
                Transactions = list,
                Pagination = pagination
            });
        }