Example #1
0
        public void UpdatePlayerScore(int uniqueKey, String playerName, int score)
        {
            GameRepository gameRepo   = new GameRepository(_context);
            int            gameRoomId = gameRepo.GetGameroomIdByUniqueKey(uniqueKey);
            var            players    = _context.Players.Where(a => a.GameroomId == gameRoomId).ToList();

            if (Validation.UpdateScoreValidation(players, playerName))
            {
                var player = _context.Players.Where(a => a.GameroomId == gameRoomId).ToList()
                             .Where(a => a.PlayerName == playerName).First();
                player.PlayerScore += score;
                Edit(player);
            }
            else
            {
                throw new Exception("Player not found!");
            }
        }
Example #2
0
        public void Create(PlayerUniqueKey playerUniqueKey)
        {
            GameRepository gameRepo = new GameRepository(_context);
            Player         player   = new Player
            {
                PlayerName  = playerUniqueKey.PlayerName,
                PlayerScore = 0,
                GameroomId  = gameRepo.GetGameroomIdByUniqueKey(playerUniqueKey.UniqueKey)
            };

            var players = _context.Players.Where(a => a.GameroomId == player.GameroomId).ToList();

            if (Validation.CreatePlayerValidation(players, player))
            {
                _context.Players.Add(player);
                _context.SaveChanges();
            }
            else
            {
                throw new Exception("Nume deja existent!");
            }
        }