Exemple #1
0
 public bool UpdatePlayerStats(EditPlayerStats model)
 {
     using (var ctx = new ApplicationDbContext())
     {
         var entity =
             ctx
             .PlayerStats
             .Single(e => e.PlayerStatsID == model.PlayerStatsID);
         entity.PlayerStatsID       = model.PlayerStatsID;
         entity.PlayerID            = model.PlayerID;
         entity.PassingYards        = model.PassingYards;
         entity.PassingTouchdowns   = model.PassingTouchdowns;
         entity.InterceptionThrown  = model.InterceptionThrown;
         entity.RushingYards        = model.RushingYards;
         entity.RushingAttempts     = model.RushingAttempts;
         entity.RushingTouchDowns   = model.RushingTouchDowns;
         entity.ReceivingYards      = model.ReceivingYards;
         entity.Catches             = model.Catches;
         entity.ReceivingTouchDowns = model.ReceivingTouchDowns;
         entity.Fumbles             = model.Fumbles;
         entity.Tackles             = model.Tackles;
         entity.Sacks           = model.Sacks;
         entity.Interceptions   = model.Interceptions;
         entity.ForcedFumbles   = model.ForcedFumbles;
         entity.FumbleRecovery  = model.FumbleRecovery;
         entity.Safety          = model.Safety;
         entity.BlockedKick     = model.BlockedKick;
         entity.ReturnTouchDown = model.ReturnTouchDown;
         return(ctx.SaveChanges() == 1);
     }
 }
 public ActionResult Edit(EditPlayerStats cps)
 {
     if (this.ModelState.IsValid)
     {
         PlayerStatsController psc = new PlayerStatsController();
         psc.Put(cps);
         return(RedirectToAction("Index", "Home"));
     }
     else
     {
         return(View(cps));
     }
 }
        /// <summary> Changes details about a Player Stat. </summary>
        public IHttpActionResult Put(EditPlayerStats playerStats)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var service = CreatePlayerStatsService();

            if (!service.UpdatePlayerStats(playerStats))
            {
                return(InternalServerError());
            }
            return(Ok());
        }