public ActionResult Edit(int budgetId, int categoryId) { var service = CreateBudgetCategoryService(); var detail = service.GetBudgetCategoryByIds(budgetId, categoryId); var model = new BudgetCategoryEdit { BudgetId = detail.BudgetId, CategoryId = detail.CategoryId, Amount = detail.Amount }; return(View(model)); }
public bool UpdateBudgetCategory(BudgetCategoryEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .BudgetCategory .Single(e => e.BudgetId == model.BudgetId && e.CategoryId == model.CategoryId); entity.BudgetId = model.BudgetId; entity.CategoryId = model.CategoryId; entity.Amount = model.Amount; return(ctx.SaveChanges() == 1); } }
public ActionResult Edit(int budgetId, int categoryId, BudgetCategoryEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.BudgetId != budgetId && model.CategoryId != categoryId) { ModelState.AddModelError("", "BudgetId or CategoryIdMismatch"); return(View(model)); } var service = CreateBudgetCategoryService(); if (service.UpdateBudgetCategory(model)) { TempData["SaveResult"] = "Your Budget Category was updated."; return(RedirectToAction("Index")); } return(View()); }