Example #1
0
        public ActionResult Edit(int id)
        {
            var service = CreateOffenseStatsService();
            var detail  = service.GetOffenseStatsById(id);
            var model   =
                new NFLTeamStats_OffenseEdit
            {
                TeamId       = detail.TeamId,
                Team         = detail.Team,
                GamesPlayed  = detail.GamesPlayed,
                PointsForced = detail.PointsForced
            };

            return(View(model));
        }
Example #2
0
        public bool UpdateOffenseStats(NFLTeamStats_OffenseEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .NFLTeam_Offense
                    .Single(e => e.TeamId == model.TeamId);

                entity.Team         = model.Team;
                entity.GamesPlayed  = model.GamesPlayed;
                entity.PointsForced = model.PointsForced;

                return(ctx.SaveChanges() == 1);
            }
        }
Example #3
0
        public ActionResult Edit(int id, NFLTeamStats_OffenseEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (model.TeamId != id)
            {
                ModelState.AddModelError("", "Team Id Mismatch");
                return(View(model));
            }

            var service = CreateOffenseStatsService();

            if (service.UpdateOffenseStats(model))
            {
                TempData["SaveResult"] = "Offense stats were updated.";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "Offense stats could not be updated");
            return(View(model));
        }