public ActionResult Edit(int id) { var service = CreateDefenseStatsService(); var detail = service.GetDefenseStatsById(id); var model = new NFLTeamStats_DefenseEdit { TeamId = detail.TeamId, Team = detail.Team, GamesPlayed = detail.GamesPlayed, PointsAllowed = detail.PointsAllowed, }; return(View(model)); }
public bool UpdateDefenseStats(NFLTeamStats_DefenseEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .NFLTeam_Defense .Single(e => e.TeamId == model.TeamId); entity.Team = model.Team; entity.GamesPlayed = model.GamesPlayed; entity.PointsAllowed = model.PointsAllowed; return(ctx.SaveChanges() == 1); } }
public ActionResult Edit(int id, NFLTeamStats_DefenseEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.TeamId != id) { ModelState.AddModelError("", "Team Id Mismatch"); return(View(model)); } var service = CreateDefenseStatsService(); if (service.UpdateDefenseStats(model)) { TempData["SaveResult"] = "Defense stats were updated."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Defense stats could not be updated."); return(View(model)); }