Example #1
0
        // GET: BudgetCategories/Edit/5
        public ActionResult Edit(int?id, int?accountId)
        {
            if (id == null)
            {
                return(RedirectToAction("NotFound", "Error"));
            }
            BudgetCategories budgetCategories = db.BudgetCategories.Find(id);

            if (budgetCategories == null)
            {
                return(RedirectToAction("NotFound", "Error"));
            }

            var currentUser = db.Users.Find(User.Identity.GetUserId());
            var account     = db.accounts.Find(accountId);

            if (currentUser.HouseholdId != account.HouseholdId)
            {
                return(RedirectToAction("Index", "Home", new { intent = true, malIntent = true }));
            }

            ViewBag.BudgetId   = new SelectList(db.budgets, "Id", "Id", budgetCategories.BudgetId);
            ViewBag.CategoryId = new SelectList(db.categories, "Id", "Name", budgetCategories.CategoryId);
            return(View(budgetCategories));
        }
Example #2
0
        public ActionResult DeleteConfirmed(int id)
        {
            BudgetCategories budgetCategories = db.BudgetCategories.Find(id);

            db.BudgetCategories.Remove(budgetCategories);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Example #3
0
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            BudgetCategories budgetCategories = db.BudgetCategories.Find(id);

            if (budgetCategories == null)
            {
                return(HttpNotFound());
            }
            return(View(budgetCategories));
        }
Example #4
0
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(RedirectToAction("NotFound", "Error"));
            }
            BudgetCategories budgetCategories = db.BudgetCategories.Find(id);

            if (budgetCategories == null)
            {
                return(RedirectToAction("NotFound", "Error"));
            }
            return(View(budgetCategories));
        }
Example #5
0
        public ActionResult Create([Bind(Include = "Id,CategoryId,BudgetId,AmountDedicated")] BudgetCategories budgetCategories)
        {
            if (ModelState.IsValid)
            {
                var budgetId  = (int)TempData["BudgetId"];
                var budget    = db.budgets.Find(budgetId);
                var accountId = db.accounts.Where(a => a.BudgetId == budgetId).FirstOrDefault();

                budget.Amount             = budget.Amount + budgetCategories.AmountDedicated;
                budgetCategories.BudgetId = budgetId;
                db.BudgetCategories.Add(budgetCategories);
                db.SaveChanges();
                return(RedirectToAction("Index", "Budgets", new { accountId.Id }));
            }

            ViewBag.BudgetId   = new SelectList(db.budgets, "Id", "Id", budgetCategories.BudgetId);
            ViewBag.CategoryId = new SelectList(db.categories, "Id", "Name", budgetCategories.CategoryId);
            return(View(budgetCategories));
        }