예제 #1
0
 // GET api/Games
 public HttpResponseMessage Get()
 {
     using (WebAPI_FP_TournamentGamesEntities entities = new WebAPI_FP_TournamentGamesEntities())
     {
         return(Request.CreateResponse(HttpStatusCode.OK, entities.GamesResoluts.ToList()));
     }
 }
예제 #2
0
 // PUT api/Games/5
 public HttpResponseMessage Put(int id, [FromBody] GamesResolut value)
 {
     using (WebAPI_FP_TournamentGamesEntities entities = new WebAPI_FP_TournamentGamesEntities())
     {
         GamesResolut wanted = entities.GamesResoluts.FirstOrDefault(t => t.ID == id);
         if (wanted != null)
         {
             wanted.Game_Name = value.Game_Name;
             wanted.Player1   = value.Player1;
             wanted.Player2   = value.Player2;
             wanted.Who_Won_  = value.Who_Won_;
             //entities.SaveChanges();
             try
             {
                 //db.SaveChanges();
                 entities.SaveChanges();
             }
             catch (DbEntityValidationException ex)
             {
                 Console.WriteLine(ex);
             }
             return(Request.CreateResponse(HttpStatusCode.Accepted, wanted));
         }
         else
         {
             return(Request.CreateResponse(HttpStatusCode.NotFound, string.Format("The game with id: {0} not found", id)));
         }
     }
 }
예제 #3
0
 // POST api/Games
 public HttpResponseMessage Post([FromBody] GamesResolut value)
 {
     using (WebAPI_FP_TournamentGamesEntities entities = new WebAPI_FP_TournamentGamesEntities())
     {
         entities.GamesResoluts.Add(value);
         entities.SaveChanges();
         return(Request.CreateResponse(HttpStatusCode.Created, new Uri(Request.RequestUri + value.ID.ToString())));
     }
 }
예제 #4
0
 // GET api/Games/5
 public HttpResponseMessage Get(int id)
 {
     using (WebAPI_FP_TournamentGamesEntities entities = new WebAPI_FP_TournamentGamesEntities())
     {
         GamesResolut wanted = entities.GamesResoluts.FirstOrDefault(t => t.ID == id);
         if (wanted != null)
         {
             return(Request.CreateResponse(HttpStatusCode.OK, wanted));
         }
         else
         {
             return(Request.CreateResponse(HttpStatusCode.NotFound, string.Format("The game with id: {0} not found", id)));
         }
     }
 }
예제 #5
0
 public HttpResponseMessage GetByName(string name)
 {
     using (WebAPI_FP_TournamentGamesEntities entities = new WebAPI_FP_TournamentGamesEntities())
     {
         List <GamesResolut> wanted = entities.GamesResoluts.Where(t => (t.Player1.ToUpper() == name.ToUpper()) || (t.Player2.ToUpper() == name.ToUpper())).ToList();
         if (wanted.Count > 0)
         {
             return(Request.CreateResponse(HttpStatusCode.OK, wanted));
         }
         else
         {
             return(Request.CreateResponse(HttpStatusCode.NotFound, string.Format("The game with Player: {0} not found", name)));
         }
     }
 }
 // GET api/GamesResults/5
 public HttpResponseMessage Get(int id)
 {
     using (WebAPI_FP_TournamentGamesEntities entities = new WebAPI_FP_TournamentGamesEntities())
     {
         GamesResult game = entities.GamesResults.FirstOrDefault(t => t.ID == id);
         if (game != null)
         {
             return(Request.CreateResponse(HttpStatusCode.OK, game));
         }
         else
         {
             return(Request.CreateResponse(HttpStatusCode.NotFound, string.Format("Game with id : {0} , NOT FOUND!!!", id)));
         }
     }
 }
 public HttpResponseMessage GetByPlayerName(string playerName)
 {
     using (WebAPI_FP_TournamentGamesEntities entities = new WebAPI_FP_TournamentGamesEntities())
     {
         List <GamesResult> gameList = (entities.GamesResults.Where(t => ((t.Player1.ToUpper() == playerName.ToUpper()) ||
                                                                          (t.Player2.ToUpper() == playerName.ToUpper())))).ToList();
         if (gameList.Count > 0)
         {
             return(Request.CreateResponse(HttpStatusCode.OK, gameList));
         }
         else
         {
             return(Request.CreateResponse(HttpStatusCode.NotFound, string.Format("Game with id : {0} , NOT FOUND!!!", playerName)));
         }
     }
 }
 // DELETE api/GamesResults/5
 public HttpResponseMessage Delete(int id)
 {
     using (WebAPI_FP_TournamentGamesEntities entities = new WebAPI_FP_TournamentGamesEntities())
     {
         GamesResult game = entities.GamesResults.FirstOrDefault(t => t.ID == id);
         if (game != null)
         {
             entities.GamesResults.Remove(game);
             entities.SaveChanges();
             return(Request.CreateResponse(HttpStatusCode.Accepted, string.Format("Game with id: {0} , was deleted.", id)));
         }
         else
         {
             return(Request.CreateResponse(HttpStatusCode.NotFound, string.Format("Game with id : {0} , NOT FOUND!!!", id)));
         }
     }
 }
 public HttpResponseMessage GetBySearch(string gameName = null, string player1Name = null, string player2Name = null, string whoWon = null)
 {
     using (WebAPI_FP_TournamentGamesEntities entities = new WebAPI_FP_TournamentGamesEntities())
     {
         List <GamesResult> gameList = entities.GamesResults.Where(t => gameName != null ? t.Game_Name.ToUpper().Contains(gameName.ToUpper()) : true)
                                       .Where(t => player1Name != null ? t.Player1.ToUpper().Contains(player1Name.ToUpper()) : true)
                                       .Where(t => player2Name != null ? t.Player2.ToUpper().Contains(player2Name.ToUpper()) : true)
                                       .Where(t => whoWon != null ? t.Who_Won_.ToUpper().Contains(whoWon.ToUpper()) : true).ToList();
         if (gameList.Count > 0)
         {
             return(Request.CreateResponse(HttpStatusCode.OK, gameList));
         }
         else
         {
             return(Request.CreateResponse(HttpStatusCode.NotFound, string.Format("Game with wished fields NOT FOUND!!!")));
         }
     }
 }
예제 #10
0
 public HttpResponseMessage Get(int id = -1, string gameName = null, string player1 = null, string player2 = null, string whoWon = null)
 {
     using (WebAPI_FP_TournamentGamesEntities entities = new WebAPI_FP_TournamentGamesEntities())
     {
         List <GamesResolut> wanted = entities.GamesResoluts.Where(t => id != -1 ? t.ID == id : true)
                                      .Where(t => gameName != null ? t.Game_Name.ToUpper() == gameName.ToUpper() : true)
                                      .Where(t => player1 != null ? t.Player1.ToUpper() == player1.ToUpper() : true)
                                      .Where(t => player2 != null ? t.Player2.ToUpper() == player2.ToUpper() : true)
                                      .Where(t => whoWon != null ? t.Who_Won_.ToUpper() == whoWon.ToUpper() : true).ToList();
         if (wanted != null)
         {
             return(Request.CreateResponse(HttpStatusCode.OK, wanted));
         }
         else
         {
             return(Request.CreateResponse(HttpStatusCode.NotFound, "The game not found"));
         }
     }
 }
예제 #11
0
 // PUT api/GamesResults/5
 public HttpResponseMessage Put(int id, [FromBody] GamesResult game)
 {
     using (WebAPI_FP_TournamentGamesEntities entities = new WebAPI_FP_TournamentGamesEntities())
     {
         GamesResult gameUpdate = entities.GamesResults.FirstOrDefault(t => t.ID == id);
         if (gameUpdate != null)
         {
             gameUpdate.Game_Name = game.Game_Name;
             gameUpdate.Player1   = game.Player1;
             gameUpdate.Player2   = game.Player2;
             gameUpdate.Who_Won_  = game.Who_Won_;
             entities.SaveChanges();
             return(Request.CreateResponse(HttpStatusCode.Accepted, gameUpdate));
         }
         else
         {
             return(Request.CreateResponse(HttpStatusCode.NotFound, string.Format("Game with id : {0} , NOT FOUND!!!", id)));
         }
     }
 }