Beispiel #1
0
        public ActionResult GetAmountForCategory(int MonthId)
        {
            var budgetRepo = new BudgetRepository(Properties.Settings.Default._connectionString);

            var List         = budgetRepo.CategoryListWithAmounts(MonthId);
            var CategoryList = budgetRepo.GetAllCategories();

            List <CategoryWithAmountForMonth> CategoriesWithAMount = new List <CategoryWithAmountForMonth>();

            foreach (Category C in CategoryList)
            {
                CategoryWithAmountForMonth CategoryWithSum = new CategoryWithAmountForMonth();

                CategoryWithSum.CategoryName = C.CategoryName;
                CategoryWithSum.Sum          = List.Where(D => D.Category.CategoryName == C.CategoryName).Select(D => D.Amount).Sum();

                CategoriesWithAMount.Add(CategoryWithSum);
                //  CategoryWithSum.Sum = List.Select((D => D.Amount)).Where (D => D.am)
            }
            return(Json(CategoriesWithAMount.Select(C => new
            {
                categoryName = C.CategoryName,
                amount = C.Sum
            }), JsonRequestBehavior.AllowGet));
        }
Beispiel #2
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));
        }