public ActionResult Edit(int id) { var service = CreateReceivingService(); var detail = service.GetReceivingStatsById(id); var model = new NFLPlayerStats_ReceivingEdit { PlayerId = detail.PlayerId, Targets = detail.Targets, Receptions = detail.Receptions, Touchdowns = detail.Touchdowns, Yards = detail.Yards }; return(View(model)); }
public bool UpdateReceivingStats(NFLPlayerStats_ReceivingEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .NFLPlayer_Receiving .Single(e => e.PlayerId == model.PlayerId); entity.Targets = model.Targets; entity.Receptions = model.Receptions; entity.Touchdowns = model.Touchdowns; entity.Yards = model.Yards; return(ctx.SaveChanges() == 1); } }
public ActionResult Edit(int id, NFLPlayerStats_ReceivingEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.PlayerId != id) { ModelState.AddModelError("", "Id Mismatch"); return(View(model)); } var service = CreateReceivingService(); if (service.UpdateReceivingStats(model)) { TempData["SaveResult"] = "Receiving stats were updated."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Receiving stats could not be updated."); return(View()); }