public ActionResult Edit(int id, TestStatsEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.TestId != id) { ModelState.AddModelError("", "Id Mismatch"); return(View(model)); } var service = CreateTestService(); if (service.UpdateTestStats(model)) { TempData["SaveResult"] = "Your Cricketer was updated."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Your Cricketer could not be updated."); return(View(model)); }
public ActionResult Edit(int id) { var service = CreateTestService(); var detail = service.GetTestStatsEditById(id); var model = new TestStatsEdit { TestId = detail.TestId, DoubleCenturyTest = detail.DoubleCenturyTest, HalfCenturyTest = detail.HalfCenturyTest, CricketerId = detail.CricketerId }; return(View(model)); }
public bool UpdateTestStats(TestStatsEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .TestStatss .Single(e => e.TestId == model.TestId && e.UserId == _userId); entity.DoubleCenturyTest = model.DoubleCenturyTest; entity.HalfCenturyTest = model.HalfCenturyTest; return(ctx.SaveChanges() == 1); } }