public ActionResult MonthlyBudgetView()
        {
            MonthlyBudgetViewModel model = new MonthlyBudgetViewModel();

            //model.CategoryList = db.category;
            //model.BudgetList = db.monthlyBudget;
            ViewBag.CategoryId = new SelectList(db.category, "Id", "CategoryName", model.CategoryId);
            return(View(model));
        }
        public ActionResult MonthlyBudgetView(MonthlyBudgetViewModel model, string BudgetMonth)
        {
            model.CategoryList = db.category;

            var newMonthlyBuget = new MonthlyBudget
            {
                CategoryId   = model.CategoryId,
                BudgetMonth  = model.BudgetMonth,
                BudgetAmount = model.BudgetAmount,
                ActualAmount = 0,
                Difference   = 0
            };

            db.monthlyBudget.Add(newMonthlyBuget);
            db.SaveChanges();
            model.BudgetList = db.monthlyBudget.Where(x => x.BudgetMonth == BudgetMonth).ToList();

            ViewBag.CategoryId = new SelectList(db.category, "Id", "CategoryName", model.CategoryId);
            return(View(model));
        }
예제 #3
0
        public MonthlyBudgetsViewModel GetMonthlyBudget(string userId)
        {
            var allCategories = DbContext.BudgetCategories;
            var viewModel     = new MonthlyBudgetsViewModel();

            foreach (var category in allCategories)
            {
                var budgetCategory = new MonthlyBudgetViewModel()
                {
                    Item       = category.Name,
                    CurrentSum = DbContext.Expenditures
                                 .Where(a => a.SpenderId == userId && a.BudgetCategoryId == category.Id && a.Date.Month == DateTime.Now.Month)
                                 .Sum(a => a.Money),
                    SetGoal = category.SetGoal
                };
                viewModel.CurrentMonthlyBudgets.Add(budgetCategory);
            }

            return(viewModel);
        }