public ActionResult Edit(int id) { var service = CreatePassingStatsService(); var detail = service.GetPlayerPassingStatsById(id); var model = new NFLPlayerStats_PassingEdit { PlayerId = detail.PlayerId, Player = detail.Player, Completions = detail.Completions, Attempts = detail.Attempts, Yards = detail.Yards }; return(View(model)); }
public bool UpdatePassingStats(NFLPlayerStats_PassingEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .NFLPlayer_Passing .Single(e => e.PlayerId == model.PlayerId); entity.Player = model.Player; entity.Completions = model.Completions; entity.Attempts = model.Attempts; entity.Yards = model.Yards; return(ctx.SaveChanges() == 1); } }
public ActionResult Edit(int id, NFLPlayerStats_PassingEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.PlayerId != id) { ModelState.AddModelError("", "Player ID mismatch"); return(View(model)); } var service = CreatePassingStatsService(); if (service.UpdatePassingStats(model)) { TempData["SaveResult"] = "Passing Stats updated"; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Passing stats could not be updated."); return(View()); }