public ActionResult Edit(int CategoryId, float Amount, int RepeatFrequencyId, int DayOfMonth, int BudgetId, int Id) { BudgetItem budgetItem = new BudgetItem(); budgetItem.Amount = Amount; budgetItem.CategoryId = CategoryId; budgetItem.RepeatFrequencyId = RepeatFrequencyId; budgetItem.DayOfMonth = DayOfMonth; budgetItem.BudgetId = BudgetId; budgetItem.Id = Id; if (ModelState.IsValid) { db.Entry(budgetItem).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ApplicationUser currUser = db.Users.Find(User.Identity.GetUserId()); ViewBag.HouseholdId = currUser.HouseholdId; ViewBag.BudgetId = currUser.Household.Budgets.First().Id; ViewBag.CategoryId = new SelectList(db.Category, "Id", "Name", budgetItem.CategoryId); ViewBag.RepeatFrequencyId = new SelectList(db.RepeatFrequency, "Id", "Frequency", budgetItem.RepeatFrequencyId); return(View(budgetItem)); }
// GET: Budgets/Details/5 public ActionResult Details(int?id) { ApplicationUser currUser = db.Users.Find(User.Identity.GetUserId()); if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } BudgetItem budgetItem = db.BudgetItem.Find(id); if (budgetItem == null) { return(HttpNotFound()); } BudgetViewItem viewItem = CloneObject(budgetItem); //viewItem.CategoryName = budgetItem.Category.Name; //viewItem.BudgetItemId = budgetItem.Id; //viewItem.BudgetTotal = budgetItem.Amount; ViewBag.Transactions = db.Transaction.Where(o => o.Account.HouseholdId == currUser.HouseholdId && o.CategoryId == budgetItem.CategoryId).ToList(); viewItem = LinkTransactionsItem(viewItem, ViewBag.Transactions); return(View(viewItem)); }
public ActionResult DeleteConfirmed(int id) { BudgetItem budgetItem = db.BudgetItem.Find(id); db.BudgetItem.Remove(budgetItem); db.SaveChanges(); return(RedirectToAction("Index")); }
private BudgetViewItem CloneObject(BudgetItem item) { var javaScriptSerializer = new JavaScriptSerializer(); BudgetViewItem itemList = new BudgetViewItem(); itemList.BudgetItemId = item.Id; itemList.CategoryName = item.Category.Name; itemList.CategoryId = item.CategoryId; itemList.BudgetTotal = item.Amount; itemList.TotalValue = javaScriptSerializer.Serialize(item.Amount); return(itemList); }
// GET: Budgets/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } BudgetItem budget = db.BudgetItem.Find(id); if (budget == null) { return(HttpNotFound()); } return(View(budget)); }
public ActionResult Create(DateTime DayOfMonth, int RepeatFrequencyId, int CategoryId, float Amount, int BudgetId) { // check for existing budget for set category ApplicationUser currUser = db.Users.Find(User.Identity.GetUserId()); int categorySum = 0; int budgetItemId = 0; foreach (Budget userBudget in currUser.Household.Budgets) { int count = 0; count = db.BudgetItem.Where(i => i.CategoryId == CategoryId && userBudget.Id == i.BudgetId).Count(); categorySum += count; if (count > 0) { budgetItemId = db.BudgetItem.Where(i => i.CategoryId == CategoryId && userBudget.Id == i.BudgetId).FirstOrDefault().Id; } } if (categorySum > 0) { return(RedirectToAction("CreateError", new { id = budgetItemId })); } BudgetItem budget = new BudgetItem(); budget.DayOfMonth = DayOfMonth.Day; budget.BudgetId = BudgetId; budget.RepeatFrequencyId = RepeatFrequencyId; budget.CategoryId = CategoryId; budget.Amount = Amount; if (ModelState.IsValid) { db.BudgetItem.Add(budget); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.HouseholdId = currUser.HouseholdId; ViewBag.BudgetId = currUser.Household.Budgets.First().Id; ViewBag.CategoryId = new SelectList(db.Category, "Id", "Name"); ViewBag.RepeatFrequencyId = new SelectList(db.RepeatFrequency, "Id", "Frequency"); return(View()); }
// GET: Budgets/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } BudgetItem budgetItem = db.BudgetItem.Find(id); if (budgetItem == null) { return(HttpNotFound()); } ApplicationUser currUser = db.Users.Find(User.Identity.GetUserId()); ViewBag.HouseholdId = currUser.HouseholdId; ViewBag.BudgetId = currUser.Household.Budgets.First().Id; ViewBag.CategoryId = new SelectList(db.Category, "Id", "Name", budgetItem.CategoryId); ViewBag.RepeatFrequencyId = new SelectList(db.RepeatFrequency, "Id", "Frequency", budgetItem.RepeatFrequencyId); return(View(budgetItem)); }