// GET: Budgets/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Budget budget = db.Budgets.Find(id);

            if (budget == null)
            {
                return(HttpNotFound());
            }

            // Build & populate BudgetTransactionsViewModel
            BudgetTransactionsViewModel btViewModel = new BudgetTransactionsViewModel();

            btViewModel.Budget = budget;
            int currentUserHouseholdId = User.Identity.GetHouseholdId().Value;

            btViewModel.Transactions = db.Transactions.Where(t => t.Account.HouseholdId == currentUserHouseholdId).Where(t => t.Void == false).Where(t => t.CategoryId == budget.CategoryId).ToList();
            decimal currentTransactionsTotal = db.Transactions.Where(t => t.Account.HouseholdId == currentUserHouseholdId).Where(t => t.Void == false).Where(t => t.CategoryId == budget.CategoryId).Sum(t => (decimal?)t.Amount) ?? 0;

            btViewModel.TotalTransactions        = currentTransactionsTotal * -1;
            btViewModel.DisplayTotalTransactions = currentTransactionsTotal;
            return(View(btViewModel));

            //return View(budget);
        }
        public ActionResult Index()
        {
            // Build & populate DashTransactionsViewModel
            List <DashTransactionsViewModel> dashViewModel = new List <DashTransactionsViewModel>();

            int currentUserHouseholdId = User.Identity.GetHouseholdId().Value;
            int expenseTypeId          = db.TransactionTypes.First(t => t.Name == "Expense").Id;
            int incomeTypeId           = db.TransactionTypes.First(t => t.Name == "Income").Id;

            List <BankAccount> currentUserBankAccounts = db.BankAccounts.Where(b => b.HouseholdId == currentUserHouseholdId).ToList();

            int currentYear = DateTimeOffset.UtcNow.Year;


            foreach (var account in currentUserBankAccounts)
            {
                DashTransactionsViewModel currentAccountVM = new DashTransactionsViewModel();

                decimal currentExpenseTotal = account.Transactions.Where(t => t.DateOfTransaction.Year == currentYear).Where(t => t.Category.TransactionTypeId == expenseTypeId).Sum(t => (decimal?)t.Amount) ?? 0;
                decimal currentIncomeTotal  = account.Transactions.Where(t => t.DateOfTransaction.Year == currentYear).Where(t => t.Category.TransactionTypeId == incomeTypeId).Sum(t => (decimal?)t.Amount) ?? 0;

                currentAccountVM.AccountName = account.Name;
                currentAccountVM.TotalExpenseTransactions = currentExpenseTotal * -1;
                currentAccountVM.TotalIncomeTransactions  = currentIncomeTotal;

                List <Transaction> currentAccountTransactions = new List <Transaction>();
                currentAccountTransactions   = db.Transactions.Where(t => t.DateOfTransaction.Year == currentYear).Where(t => t.Account.HouseholdId == currentUserHouseholdId).Where(t => t.AccountId == account.Id).OrderByDescending(t => t.DateOfTransaction).Take(10).ToList();
                currentAccountVM.Transaction = currentAccountTransactions;

                currentAccountVM.CurrentYear = currentYear;

                if (account.Balance < 0)
                {
                    currentAccountVM.AccountOverdrawn = true;
                }
                else
                {
                    currentAccountVM.AccountOverdrawn = false;
                }

                dashViewModel.Add(currentAccountVM);
            }

            List <BudgetTransactionsViewModel> btVM = new List <BudgetTransactionsViewModel>();
            List <Budget> currentUserBudgets        = db.Budgets.Where(b => b.HouseholdId == currentUserHouseholdId).ToList();

            foreach (var budget in currentUserBudgets)
            {
                // Build & populate BudgetTransactionsViewModel
                BudgetTransactionsViewModel btViewModel = new BudgetTransactionsViewModel();
                btViewModel.Budget       = budget;
                btViewModel.Transactions = db.Transactions.Where(t => t.Account.HouseholdId == currentUserHouseholdId).Where(t => t.CategoryId == budget.CategoryId).ToList();
                decimal currentTransactionsTotal = db.Transactions.Where(t => t.Account.HouseholdId == currentUserHouseholdId).Where(t => t.CategoryId == budget.CategoryId).Sum(t => (decimal?)t.Amount) ?? 0;
                btViewModel.TotalTransactions        = currentTransactionsTotal * -1;
                btViewModel.DisplayTotalTransactions = currentTransactionsTotal;

                btVM.Add(btViewModel);
            }

            ViewBag.DashBudgets = btVM;

            return(View(dashViewModel));
        }