public HttpResponseMessage GetAllGame()
 {
     using (db = new GamePlayerEntities())
     {
         return(Request.CreateResponse(HttpStatusCode.OK, db.Game.ToList()));
     }
 }
 public HttpResponseMessage Post([FromBody] Game game)
 {
     using (db = new GamePlayerEntities())
     {
         db.Game.Add(game);
         db.SaveChanges();
         return(Request.CreateResponse(HttpStatusCode.Accepted));
     }
 }
 public HttpResponseMessage GetWithId(int id)
 {
     using (db = new GamePlayerEntities())
     {
         Game game = db.Game.FirstOrDefault(ID => ID.ID.Equals(id));
         if (game != null)
         {
             return(Request.CreateResponse(HttpStatusCode.OK, game));
         }
         else
         {
             return(Request.CreateResponse(HttpStatusCode.NotFound, game));
         }
     }
 }
        // DELET api/Game/5
        public HttpResponseMessage Delete(int id)
        {
            using (db = new GamePlayerEntities())
            {
                Game game = db.Game.FirstOrDefault(ID => ID.ID.Equals(id));
                if (game != null)
                {
                    db.Game.Remove(game);
                    db.SaveChanges();

                    return(Request.CreateResponse(HttpStatusCode.OK, "The game" + game.ID + "remove"));
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound));
                }
            }
        }
        // PUT api/Game/5
        public HttpResponseMessage Put(int id, [FromBody] Game gameBody)
        {
            using (db = new GamePlayerEntities())
            {
                Game game = db.Game.FirstOrDefault(ID => ID.ID.Equals(id));
                if (game != null)
                {
                    game.Player_one = gameBody.Player_one;
                    game.Player_two = gameBody.Player_two;
                    game.who_won    = gameBody.who_won;
                    game.Game_Name  = gameBody.Game_Name;
                    db.SaveChanges();

                    return(Request.CreateResponse(HttpStatusCode.Accepted));
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound));
                }
            }
        }
        public HttpResponseMessage Get(int id = -1, string gameName = null, string playerOne = null, string playerTwo = null, string who_Won = null)
        {
            using (db = new GamePlayerEntities())
            {
                List <Game> listGame = db.Game
                                       .Where(g => gameName != null ? g.Game_Name.ToLower().StartsWith(gameName.ToLower()) : true)

                                       .Where(p1 => playerOne != null ? p1.Player_one.ToLower().StartsWith(playerOne.ToLower()) : true)
                                       .Where(p2 => playerTwo != null ? p2.Player_two.ToLower().StartsWith(playerTwo.ToLower()) : true)
                                       .Where(ww => who_Won != null ? ww.who_won.ToLower().StartsWith(who_Won.ToLower()) : true)
                                       .Where(idGame => id > -1 ? idGame.ID.Equals(id) : true).ToList();


                if (listGame.Count > 0)
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, listGame));
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound));
                }
            }
        }