예제 #1
0
 // GET api/Games
 public HttpResponseMessage Get()
 {
     using (GamesDBEntities entities = new GamesDBEntities())
     {
         return(Request.CreateResponse(HttpStatusCode.OK, entities.tblGames.ToList()));
     }
 }
 public void AddGame(GAME game)
 {
     using (var gameContext = new GamesDBEntities())
     {
         gameContext.GAMES.Add(game);
         gameContext.SaveChanges();
     }
 }
예제 #3
0
 // POST api/Games
 public HttpResponseMessage Post([FromBody] tblGame game)
 {
     using (GamesDBEntities entities = new GamesDBEntities())
     {
         entities.tblGames.Add(game);
         entities.SaveChanges();
         return(Request.CreateResponse(HttpStatusCode.Created, new Uri(Request.RequestUri + "/" + game.GameID.ToString())));
     }
 }
예제 #4
0
 public HttpResponseMessage GetByPlayer(string player)
 {
     using (GamesDBEntities entities = new GamesDBEntities())
     {
         List <tblGame> gameList = entities.tblGames.Where(g => g.Player1.ToLower().StartsWith(player.ToLower()) || g.Player2.ToLower().StartsWith(player.ToLower())).ToList();
         if (gameList.Count > 0)
         {
             return(Request.CreateResponse(HttpStatusCode.OK, player));
         }
         else
         {
             return(Request.CreateResponse(HttpStatusCode.NotFound, string.Format($"Game with Name {player} was not Found")));
         }
     }
 }
예제 #5
0
 // GET api/Games/5
 public HttpResponseMessage Get(int id)
 {
     using (GamesDBEntities entities = new GamesDBEntities())
     {
         tblGame game = entities.tblGames.FirstOrDefault(g => g.GameID == id);
         if (game != null)
         {
             return(Request.CreateResponse(HttpStatusCode.OK, game));
         }
         else
         {
             return(Request.CreateResponse(HttpStatusCode.NotFound, string.Format($"Game with ID {id} was not Found")));
         }
     }
 }
예제 #6
0
 // DELETE api/Games/5
 public HttpResponseMessage Delete(int id)
 {
     using (GamesDBEntities entities = new GamesDBEntities())
     {
         tblGame game = entities.tblGames.FirstOrDefault(g => g.GameID == id);
         if (game != null)
         {
             entities.tblGames.Remove(game);
             entities.SaveChanges();
             return(Request.CreateResponse(HttpStatusCode.Accepted, string.Format($"Game with ID {id} was Deleted")));
         }
         else
         {
             return(Request.CreateResponse(HttpStatusCode.NotFound, string.Format($"Game with ID {id} was not Found")));
         }
     }
 }
        public void EditGame(int gameId)
        {
            using (var gameContext = new GamesDBEntities())
            {
                var query = from game in GDBEntities.GAMES
                            where game.Id == gameId
                            select game;

                foreach (GAME game in query)
                {
                    game.Complete         = true;
                    game.DateOfCompletion = DateTime.Today;
                }


                gameContext.SaveChanges();
            }
        }
예제 #8
0
 // PUT api/Games/5
 public HttpResponseMessage Put(int id, [FromBody] tblGame game)
 {
     using (GamesDBEntities entities = new GamesDBEntities())
     {
         tblGame game_To_Update = entities.tblGames.FirstOrDefault(g => g.GameID == id); // LINQ - Check if Found ID First or Default
         if (game_To_Update != null)
         {
             game_To_Update.Game_Name = game.Game_Name;
             game_To_Update.Player1   = game.Player1;
             game_To_Update.Player2   = game.Player2;
             game_To_Update.Who_won   = game.Who_won;
             entities.SaveChanges();
             return(Request.CreateResponse(HttpStatusCode.Accepted, string.Format($"game with ID {id} Updated")));
         }
         else
         {
             return(Request.CreateResponse(HttpStatusCode.NotFound, string.Format($"game wite ID {id} not Found")));
         }
     }
 }
예제 #9
0
 public HttpResponseMessage GetBySearch(int gameID = 0, string gameName = null, string player1 = null, string player2 = null, string whoWon = null)
 {
     using (GamesDBEntities entities = new GamesDBEntities())
     {
         List <tblGame> gameList = entities.tblGames.Where(g => gameID > 0 ? g.GameID == gameID : true).
                                   Where(g => gameName != null ? g.Game_Name.ToLower().StartsWith(gameName.ToLower()): true).
                                   Where(g => player1 != null ? g.Player1.ToLower().StartsWith(player1.ToLower()): true).
                                   Where(g => player2 != null ? g.Player2.ToLower().StartsWith(player2.ToLower()): true).
                                   Where(g => whoWon != null ? g.Who_won.ToLower().StartsWith(whoWon.ToLower()): true)
                                   .ToList();
         if (gameList.Count > 0)
         {
             return(Request.CreateResponse(HttpStatusCode.OK, gameList));
         }
         else
         {
             return(Request.CreateResponse(HttpStatusCode.NotFound, string.Format("game whit this search fild is not found")));
         }
     }
 }
        public List <GAME> RetrieveGames(string console, bool complete)
        {
            using (var gameContext = new GamesDBEntities())
            {
                var query = from game in GDBEntities.GAMES
                            select game;
                if (complete)
                {
                    switch (console)
                    {
                    case "NES":
                        query = from game in GDBEntities.GAMES
                                where game.Console == "NES" && game.Complete == true
                                select game;
                        return(query.ToList <GAME>());

                    case "SNES":
                        query = from game in GDBEntities.GAMES
                                where game.Console == "SNES" && game.Complete == true
                                select game;
                        return(query.ToList <GAME>());

                    case "N64":
                        query = from game in GDBEntities.GAMES
                                where game.Console == "N64" && game.Complete == true
                                select game;
                        return(query.ToList <GAME>());

                    case "GCN":
                        query = from game in GDBEntities.GAMES
                                where game.Console == "GCN" && game.Complete == true
                                select game;
                        return(query.ToList <GAME>());

                    case "Wii":
                        query = from game in GDBEntities.GAMES
                                where game.Console == "Wii" && game.Complete == true
                                select game;
                        return(query.ToList <GAME>());

                    default:
                        return(query.ToList <GAME>());
                    }
                }
                else
                {
                    switch (console)
                    {
                    case "NES":
                        query = from game in GDBEntities.GAMES
                                where game.Console == "NES"
                                select game;
                        return(query.ToList <GAME>());

                    case "SNES":
                        query = from game in GDBEntities.GAMES
                                where game.Console == "SNES"
                                select game;
                        return(query.ToList <GAME>());

                    case "N64":
                        query = from game in GDBEntities.GAMES
                                where game.Console == "N64"
                                select game;
                        return(query.ToList <GAME>());

                    case "GCN":
                        query = from game in GDBEntities.GAMES
                                where game.Console == "GCN"
                                select game;
                        return(query.ToList <GAME>());

                    case "Wii":
                        query = from game in GDBEntities.GAMES
                                where game.Console == "Wii"
                                select game;
                        return(query.ToList <GAME>());

                    default:
                        return(query.ToList <GAME>());
                    }
                }
            }
        }
예제 #11
0
 public BaseRepository(GamesDBEntities context)
 {
     Context = context;
 }