public ActionResult InsertBudgetGoal(BudgetGoalModelView model) { //repopulate the dropdownlist model.category = GetSelectListItems(GetAllCategories()); BudgetGoal newBudgetGoal = new BudgetGoal(); newBudgetGoal = model.budgetGoal; //insert for next month newBudgetGoal.ClientID = CLIENT_ID; newBudgetGoal.BudgetPointValue = 25; if (newBudgetGoal.BudgetGoalID == 0) //create new category { newBudgetGoal.Month = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1); newBudgetGoal.Status = "A"; dbContext.BudgetGoals.Add(newBudgetGoal); } else //we're just updating a current budget { dbContext.Entry(newBudgetGoal).State = EntityState.Modified; } //ignore validation errors on Month and BudgetGoalId ---temporary fix? ModelState.Remove("budgetGoal.Month"); ModelState.Remove("budgetGoal.BudgetGoalId"); if (ModelState.IsValid) { dbContext.SaveChanges(); return(RedirectToAction("index")); } return(View(model)); }
/// <summary> /// Used when user wants to create a new budget category or edit a current one. /// If the id of budget is not client's or a real one, then it returns back to the budget page /// </summary> /// <param name="id">The id of the budget category</param> /// <returns>empty budget for inserting or view of budget to edit.</returns> public ActionResult InsertBudgetGoal(int?id) { if (Session["UserID"] == null) { return(RedirectToAction("Login", "Home")); } else { CLIENT_ID = int.Parse(Session["UserID"].ToString()); } BudgetGoalModelView budget = new BudgetGoalModelView(); budget.category = GetSelectListItems(GetAllCategories()); //null ID means we are inserting a new category if (id == null) { return(View(budget)); } //let's look for it budget.budgetGoal = dbContext.BudgetGoals.Find(id); budget.budgetView = dbContext.BudgetGoals_VW.Where(x => x.BudgetGoalID == budget.budgetGoal.BudgetGoalID); if (budget.budgetGoal == null || budget.budgetGoal.ClientID != CLIENT_ID) { //we couldn't find the budget category to edit or it is not the client's, redirect return(RedirectToAction("Index")); } return(View(budget)); }
/// <summary> /// Calculate the budget of the client to display on the overview page. /// </summary> /// <returns></returns> private BudgetGoalModelView getBudgetInfo() { List <BudgetGoals_VW> BudgetGoalList = new List <BudgetGoals_VW>(); //all budgets categories the client has BudgetGoalList = dbContext.BudgetGoals_VW.Where(x => x.ClientID == CLIENT_ID && x.Status == "A").OrderBy(x => x.TransactionAmount / x.BudgetGoalAmount).ToList(); //Insert them into the view model, calculate the totals BudgetGoalModelView budgetGoal = new BudgetGoalModelView(); budgetGoal.budgetView = BudgetGoalList; budgetGoal.totalBudgeted = budgetGoal.budgetView.Select(x => x).Where(x => x.GoalCategory != 1 && x.GoalCategory != 17).Sum(x => Convert.ToDouble(x.BudgetGoalAmount)); budgetGoal.totalSpent = budgetGoal.budgetView.Select(x => x).Where(x => x.GoalCategory != 1 && x.GoalCategory != 17).Sum(x => Convert.ToDouble(x.TransactionAmount)) * -1; return(budgetGoal); }
/// <summary> /// Get the view for BudgetGoals /// </summary> // GET: BudgetGoals public ActionResult Index() { if (Session["UserID"] == null) { return(RedirectToAction("Login", "Home")); } else { CLIENT_ID = int.Parse(Session["UserID"].ToString()); } updateBudgetGoals(); List <BudgetGoals_VW> BudgetGoalList = new List <BudgetGoals_VW>(); //use the view that displays all transaction for current month BudgetGoalList = dbContext.BudgetGoals_VW.Where(x => x.ClientID == CLIENT_ID && x.Status == "A").OrderBy(x => x.TransactionAmount / x.BudgetGoalAmount).ToList(); BudgetGoalModelView budgetGoal = new BudgetGoalModelView(); budgetGoal.budgetView = BudgetGoalList; budgetGoal.totalBudgeted = budgetGoal.budgetView.Select(x => x).Where(x => x.GoalCategory != 1 && x.GoalCategory != 17).Sum(x => Convert.ToDouble(x.BudgetGoalAmount)); budgetGoal.totalSpent = budgetGoal.budgetView.Select(x => x).Where(x => x.GoalCategory != 1 && x.GoalCategory != 17).Sum(x => Convert.ToDouble(x.TransactionAmount)) * -1; return(View(budgetGoal)); }