public ActionResult Task(List<BudgetTaskCategory> taskCategories) { int sum = 0; var db = new FederalSpendingDataContext(ConfigurationManager.ConnectionStrings["FederalBudgetSpendingConnectionString"].ConnectionString); foreach (var category in taskCategories) { var categoryToSave = db.BudgetTaskCategories.Single(x => x.BudgetTaskCategoryId == category.BudgetTaskCategoryId); categoryToSave.Value = category.Value; sum += category.Value; } if (sum != 100) { ModelState.AddModelError("DoesntEqual100", "The values provided do not add up to 100%. Please correct them and try again."); return View(User.BudgetTask); } db.SubmitChanges(); return View("Success"); }
public void PostValueChange(int id, int previous, int current) { var db = new FederalSpendingDataContext(ConfigurationManager.ConnectionStrings["FederalBudgetSpendingConnectionString"].ConnectionString); db.BudgetTaskCategoryHistories.InsertOnSubmit(new BudgetTaskCategoryHistory { BudgetTaskCategoryId = id, PreviousValue = previous, CurrentValue = current, CreateDate = DateTime.Now }); db.SubmitChanges(); }