Example #1
0
        // GET: Budget
        public ActionResult Budget()
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("login", "Home"));
            }

            UserRepository UserRepo    = new UserRepository(Properties.Settings.Default._connectionString);
            User           CurrentUser = UserRepo.GetUserByEmail(User.Identity.Name);

            BudgetRepository BudgetRepo = new BudgetRepository(Properties.Settings.Default._connectionString);

            var BudgetModel = new BudgetViewModel();

            BudgetModel.CurrentUser    = BudgetRepo.UserWithHistory(CurrentUser.Id);
            BudgetModel.MonthsBudgeted = BudgetRepo.MonthYearForUser(CurrentUser.Id);
            BudgetModel.AllCategories  = BudgetRepo.GetAllCategories();
            if (BudgetModel.MonthsBudgeted.Count != 0)
            {
                //gets debits for last month budgeted
                BudgetModel.DebitsForLatestMonth = BudgetRepo.GetDebitsByMonthId(CurrentUser.Id, BudgetModel.MonthsBudgeted[BudgetModel.MonthsBudgeted.Count - 1].Id);
                BudgetModel.CreditsForLastMonth  = BudgetRepo.GetCreditsByMonthId(CurrentUser.Id, BudgetModel.MonthsBudgeted[BudgetModel.MonthsBudgeted.Count - 1].Id);
                BudgetModel.LatestMonth          = BudgetRepo.GetMonthInfo(BudgetModel.MonthsBudgeted[BudgetModel.MonthsBudgeted.Count - 1].Id);
            }

            return(View(BudgetModel));
        }