public ActionResult Edit(int id, NFLPlayerStats_RushingEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.PlayerId != id) { ModelState.AddModelError("", "Id Mismatch"); return(View(model)); } var service = CreateRushingService(); if (service.UpdateRushingStats(model)) { TempData["SaveResult"] = "Rushing stats were updated."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Rushing stats could not be updated."); return(View()); }
public ActionResult Edit(int id) { var service = CreateRushingService(); var detail = service.GetRushingStatsById(id); var model = new NFLPlayerStats_RushingEdit { PlayerId = detail.PlayerId, Attempts = detail.Attempts, Yards = detail.Yards, Touchdowns = detail.Touchdowns }; return(View(model)); }
public bool UpdateRushingStats(NFLPlayerStats_RushingEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .NFLPlayer_Rushing .Single(e => e.PlayerId == model.PlayerId); entity.Attempts = model.Attempts; entity.Yards = model.Yards; entity.Touchdowns = model.Touchdowns; return(ctx.SaveChanges() == 1); } }