Esempio n. 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));
        }
Esempio n. 2
0
        public ActionResult getMonthsBudgeted()
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("login", "Home"));
            }

            var UserRepo   = new UserRepository(Properties.Settings.Default._connectionString);
            var budgetRepo = new BudgetRepository(Properties.Settings.Default._connectionString);

            var CurrentUser = UserRepo.GetUserByEmail(User.Identity.Name);
            List <Month_Year> MonthYearList = budgetRepo.MonthYearForUser(CurrentUser.Id);


            return(Json(MonthYearList.Select(M => new
            {
                Month = M.Month.ToString(),
                Year = M.Year,
                Id = M.Id,
                MonthNum = M.Month
            }), JsonRequestBehavior.AllowGet));
        }