public IHttpActionResult PutPlayerModel(int id, PlayerModel playerModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != playerModel.PlayerID)
            {
                return(BadRequest());
            }

            db.Entry(playerModel).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PlayerModelExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Example #2
0
 public ActionResult PlayerCreate(AddPlayerBindingModels ap)
 {
     if (ModelState.IsValid)
     {
         PlayerModel p = new PlayerModel
         {
             PlayerName  = ap.Name,
             GamesPlayed = ap.Games,
             GamesWon    = ap.Won
         };
         db.player.Add(p);
         db.SaveChanges();
         return(RedirectToAction("GameView", new { playerId = p.PlayerID }));
     }
     return(View(ap));
 }