Beispiel #1
0
        public async Task <IViewComponentResult> InvokeAsync()
        {
            BarChartViewModel viewModel = await Task.Run(() =>
            {
                DateTime now                    = DateTime.Now;
                BarChartViewModel vm            = new BarChartViewModel();
                vm.MinDate                      = DateTime.MaxValue;
                vm.MaxDate                      = DateTime.MinValue;
                List <BankAccount> bankAccounts = _myFinanceService.GetBankAccounts(User.GetUserId());

                bankAccounts.Where(x => x.IsVisible).ToList().ForEach(bankAccount =>
                {
                    var categories          = _myFinanceService.GetCategories(User.GetUserId());
                    DateTime lastPaymentDay = FindLastPaymentDay(now);
                    bankAccount.Movements   = _myFinanceService.GetBankAccountMovements(User.GetUserId(), bankAccount.Id, lastPaymentDay, now);

                    foreach (var selectedCategory in categories)
                    {
                        bankAccount.Movements.GroupBy(x => x.BankAccount).ToList().ForEach(x =>
                        {
                            if (x.Key.Movements.Where(r => r.Categories != null).SelectMany(q => q.Categories).Any())
                            {
                                var items = x.Where(e => e.Categories != null && e.Categories.Any(r => r.CategoryId == selectedCategory.Id));

                                AddItemIfAnyItem(bankAccount, vm, selectedCategory, items);
                            }
                        });
                    }
                });

                return(vm);
            });

            return(View(viewModel));
        }
Beispiel #2
0
        public async Task <IViewComponentResult> InvokeAsync(PortfolioDistributionType type)
        {
            DoughnutChartViewModel portfolioDistribution = await Task.Run(() =>
            {
                DoughnutChartViewModel vm       = new DoughnutChartViewModel();
                List <BankAccount> bankAccounts = _myFinanceService.GetBankAccounts(Request.HttpContext.User.GetUserId());

                bankAccounts.Where(x => x.IsVisible).ToList().ForEach(bankAccount =>
                {
                    vm.Assets.Add(Mapper.Map <DoughnutChartItemViewModel>(bankAccount));
                });

                return(vm);
            });

            return(View(type.ToString(), portfolioDistribution));
        }
Beispiel #3
0
        public async Task <IViewComponentResult> InvokeAsync()
        {
            int graphLenght           = 20;
            int graphLenghtIntoFuture = 1;

            LineChartViewModel monthlyProgression = await Task.Run(() =>
            {
                LineChartViewModel vm           = new LineChartViewModel();
                List <BankAccount> bankAccounts = _myFinanceService.GetBankAccounts(User.GetUserId());

                bankAccounts.Where(x => x.IsVisible).ToList().ForEach(bankAccount =>
                {
                    decimal lastKnownValue = 0;

                    bankAccount.Movements = _myFinanceService.GetBankAccountMovements(User.GetUserId(), bankAccount.Id, DateTime.Now.AddDays(-graphLenght), DateTime.Now);

                    lastKnownValue = GetLastKnownValue(bankAccount, lastKnownValue);

                    var currentDay = DateTime.Now.AddDays(-graphLenght).Date;
                    for (int i = 1; i < graphLenght + graphLenghtIntoFuture; i++)
                    {
                        currentDay   = currentDay.AddDays(1);
                        var movement = bankAccount.Movements.FirstOrDefault(x => x.MovementDate.Date == currentDay);

                        lastKnownValue = UpdateLastKnownValue(bankAccount, lastKnownValue, movement);

                        vm.Movements.Add(new LineChartItemViewModel()
                        {
                            XAxis  = currentDay.ToShortDateString(),
                            Amount = lastKnownValue,
                            Color  = bankAccount.Color,
                            Group  = bankAccount.Bank.ToString(),
                        });
                    }
                });

                return(vm);
            });

            return(View(monthlyProgression));
        }
Beispiel #4
0
        public IActionResult ListAccounts()
        {
            List <BankAccount> bankAccounts = _myFinanceService.GetBankAccounts(User.GetUserId());

            return(View(Mapper.Map <AccountListViewModel>(bankAccounts)));
        }