Beispiel #1
0
        private DashboardModel GetDashboardModel(long accountId, long?sharedAccountId, bool sharedDashboard)
        {
            var model = new DashboardModel();

            var expenses = sharedDashboard
                ? ExpenseRepository.GetAccountExpenses(sharedAccountId.GetValueOrDefault())
                : ExpenseRepository.GetAccountExpenses(accountId);
            var income = sharedDashboard
                ? IncomeRepository.GetAccountIncome(sharedAccountId.GetValueOrDefault())
                : IncomeRepository.GetAccountIncome(accountId);

            model.SpentToday     = GetTotalSpentAmount(expenses, ExpenseSummaryTimePeriod.Today);
            model.SpentThisWeek  = GetTotalSpentAmount(expenses, ExpenseSummaryTimePeriod.ThisWeek);
            model.SpentThisMonth = GetTotalSpentAmount(expenses, ExpenseSummaryTimePeriod.ThisMonth);
            model.SpentThisYear  = GetTotalSpentAmount(expenses, ExpenseSummaryTimePeriod.ThisYear);

            model.ExpensesLineChart = GetLineChart(expenses);
            model.IncomeLineChart   = GetLineChart(income);
            model.PieChart          = GetPieChart(expenses);

            model.BudgetOverviewList = sharedDashboard
                ? GetBudgetOverviewChart(expenses, sharedAccountId.GetValueOrDefault())
                : GetBudgetOverviewChart(expenses, accountId);

            model.Shared = GetSharedDashboardModel(accountId, sharedAccountId, sharedDashboard);

            if (sharedDashboard || !sharedAccountId.HasValue)
            {
                model.SharedExpensesLineChart.Show = false;
                model.SpentExpensesLineChart.Show  = false;
            }
            else
            {
                var spentExpenses = ExpenseRepository.GetAccountExpensesIncludeShared(accountId);
                spentExpenses.AddRange(GetMoneyTransferAsExpense(accountId, sharedAccountId.GetValueOrDefault()));
                var sharedExpenses = ExpenseRepository.GetAccountExpenses(accountId);
                sharedExpenses.AddRange(ExpenseRepository.GetAccountExpenses(sharedAccountId.GetValueOrDefault()));
                model.SpentExpensesLineChart  = GetLineChart(spentExpenses);
                model.SharedExpensesLineChart = GetLineChart(sharedExpenses);
            }

            return(model);
        }