Exemplo n.º 1
0
        public TigerGame Add(TigerGame newGame)
        {
            _context.Games.Add(newGame);
            _context.SaveChanges();

            return(newGame);
        }
Exemplo n.º 2
0
        public UserGame Add(User user, TigerGame game)
        {
            var selectedUser = _context.Users.Where(u => u.UserName == user.UserName).FirstOrDefault();
            var selectedGame = _context.Games.Where(g => g.GameName == game.GameName).FirstOrDefault();

            if (selectedUser != null && selectedGame != null)
            {
                try
                {
                    var newUserGame = new UserGame
                    {
                        UserID = selectedUser.Id,
                        GameID = selectedGame.Id
                    };

                    _context.UserGames.Add(newUserGame);
                    _context.SaveChanges();
                    return(newUserGame);
                }catch (Exception ex)
                {
                    Console.WriteLine($"{ex.Source}: {ex.Message}");
                }
            }

            return(null);
        }
Exemplo n.º 3
0
        public async Task <bool> UserGameExists(SocketGuildUser y)
        {
            var newUser = new User
            {
                UserName = y.Mention
            };

            var newGame = new TigerGame
            {
                GameName = y.Game.ToString()
            };

            var ExistingUser = _users.Get(newUser);
            var ExistingGame = _games.Get(newGame);

            if (ExistingUser == null)
            {
                throw new UserNotFoundException("User not found!");
            }
            if (ExistingGame == null)
            {
                throw new GameNotFoundException("Game not found!");
            }


            if (_ug.Get(ExistingUser, ExistingGame) is null)
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 4
0
        private async Task AddUserGame(SocketGuildUser y)
        {
            try
            {
                // Create an ad-hoc user and game
                var newUser = new User
                {
                    UserName = y.Mention
                };
                var newGame = new TigerGame
                {
                    GameName = y.Game.ToString()
                };

                // get the actual user and game. These values have to be present in order to make the game.
                var user = _users.Get(newUser);
                var game = _games.Get(newGame);

                if (user == null)
                {
                    throw new UserNotFoundException($"{newUser.UserName} not found.");
                }
                if (game == null)
                {
                    throw new GameNotFoundException($"{newGame.GameName} not found.");
                }
                _ug.Add(user, game);

                await Log(CreateLogMessage(LogSeverity.Info, "Add usergame to usergame table", $"Added {newUser.UserName}, {newGame.GameName}."));
            }
            catch (Exception ex)
            {
                await Log(CreateLogMessage(LogSeverity.Critical, $"{ex.Source}", $"Exception: {ex.Message}"));
            }
        }
Exemplo n.º 5
0
        private TigerGame CreateNewGame(string gameName)
        {
            var newGame = new TigerGame
            {
                GameName = gameName
            };

            return(newGame);
        }
Exemplo n.º 6
0
        private bool CheckUserGameExists(TigerGame game, User user)
        {
            var selectedUserGame = _userGames.Get(user, game);

            if (selectedUserGame == null)
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 7
0
        private bool CheckGameExists(TigerGame game)
        {
            var selectedGame = _games.Get(game);

            if (selectedGame == null)
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 8
0
        public async Task <bool> GameExists(SocketGuildUser game)
        {
            var newGame = new TigerGame
            {
                GameName = game.Game.ToString()
            };

            if (_games.Get(newGame) != null)
            {
                return(true);
            }

            return(false);
        }
Exemplo n.º 9
0
        public IQueryable <UserGame> GetGameUsersLoose(TigerGame game)
        {
            var selectedGame = _context.Games.Where(g => g.GameName.Contains(game.GameName)).FirstOrDefault();

            if (selectedGame != null)
            {
                var newUserGame = new UserGame
                {
                    GameID = selectedGame.Id
                };

                return(_context.UserGames.Where(ug => ug.GameID == newUserGame.GameID).OrderBy(ug => ug.GameID == newUserGame.GameID));
            }

            return(null);
        }
Exemplo n.º 10
0
        private async Task AddGameToGameTable(SocketGuildUser game)
        {
            try
            {
                var newGame = new TigerGame
                {
                    GameName = game.Game.ToString()
                };
                _games.Add(newGame);

                await Log(CreateLogMessage(LogSeverity.Info, "Add game to game table", $"Added {newGame.GameName}"));
            }
            catch (Exception ex)
            {
                await Log(CreateLogMessage(LogSeverity.Critical, $"{ex.Source}", $"Exception: {ex.Message}"));
            }
        }
Exemplo n.º 11
0
 public TigerGame Update(TigerGame game)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 12
0
 public TigerGame GetGameById(TigerGame game)
 {
     return(_context.Games.FirstOrDefault(g => g.Id == game.Id));
 }
Exemplo n.º 13
0
 public TigerGame Get(TigerGame game)
 {
     return(_context.Games.FirstOrDefault(g => g.GameName.Equals(game.GameName)));
 }