Example #1
0
 public Player[] GetAllPlayers()
 {
     using (var db = new AvalonContext())
     {
         db.Configuration.ProxyCreationEnabled = false;
         return(db.Players.ToArray <Player>());
     }
 }
 public void DeleteGame(Game game)
 {
     using (var db = new AvalonContext())
     {
         db.Games.Remove(game);
         db.SaveChanges();
     }
 }
Example #3
0
 public Player GetPlayer(string username)
 {
     using (var db = new AvalonContext())
     {
         db.Configuration.ProxyCreationEnabled = false;
         String[] usernameArray = { username };
         return(db.Players.Find(usernameArray));
     }
 }
 public Game GetGameBy(string name)
 {
     using (var db = new AvalonContext())
     {
         //int[] gameIdArray = { gameId };
         db.Configuration.ProxyCreationEnabled = false;
         return(db.Games.Find(name));
     }
 }
Example #5
0
 public void DeletePlayer(string username)
 {
     using (var db = new AvalonContext())
     {
         String[] usernameArray  = { username };
         var      playerToDelete = db.Players.Find(usernameArray);
         db.Players.Remove(playerToDelete);
         db.SaveChanges();
     }
 }
        public int CreateGame(Game game)
        {
            int gameId;

            using (var db = new AvalonContext())
            {
                db.Games.Add(game);
                db.SaveChanges();
                gameId = game.GameId;
            }

            return(gameId);
        }
        public Game[] GetAllGames()
        {
            using (var db = new AvalonContext())
            {
                db.Configuration.ProxyCreationEnabled = false;
                var allGames = new List <Game>();

                foreach (Game game in db.Games)
                {
                    allGames.Add(game);
                }

                return(allGames.ToArray());
            }
        }
 public void UpdateGame(Game game)
 {
     using (var db = new AvalonContext())
     {
         var retrievedGame = db.Games.Find(game.GameId);
         if (retrievedGame != null)
         {
             db.Entry(retrievedGame).CurrentValues.SetValues(game);
             db.SaveChanges();
         }
         else
         {
             throw new GameGatewayException("Game with id " + game.GameId + " does not exist!");
         }
     }
 }
Example #9
0
        public void UpdatePlayer(Player player)
        {
            using (var db = new AvalonContext())
            {
                String[] usernameArray   = { player.DisplayName };
                var      retrievedPlayer = db.Players.Find(usernameArray);

                if (retrievedPlayer != null)
                {
                    db.Entry(retrievedPlayer).CurrentValues.SetValues(player);
                    db.SaveChanges();
                }
                else
                {
                    throw new PlayerGatewayException("Player with username " + player.DisplayName + " does not exist.");
                }
            }
        }
Example #10
0
        public string CreatePlayer(Player player)
        {
            using (var db = new AvalonContext())
            {
                String[] usernameArray = { player.DisplayName };
                var      playerExists  = db.Players.Find(usernameArray);
                if (playerExists == null)
                {
                    db.Players.Add(player);
                    db.SaveChanges();
                }
                else
                {
                    throw new PlayerGatewayException("Username already exists!");
                }
            }

            return(player.DisplayName);
        }