public async Task <List <PlayerDto> > GetPlayersForGame(string gameId) { var gamePlayers = await GamePlayersTable.Where(x => x.GameId == gameId).ToListAsync().ConfigureAwait(false); var result = new List <PlayerDto>(); foreach (var gamePlayer in gamePlayers) { result.Add(await GetPlayer(gamePlayer.PlayerId)); } return(result); }
private async Task CleanupGames() { var now = DateTimeOffset.Now.AddDays(-2); var games = await GamesTable.Where(x => x.CreatedAt < now).ToListAsync().ConfigureAwait(false); foreach (var game in games) { if ((int)game.GameStatus < (int)GameStatus.Started) { var gamePlayers = await GamePlayersTable.Where(x => x.GameId == game.Id).ToListAsync().ConfigureAwait(false); foreach (var gamePlayer in gamePlayers) { await GamePlayersTable.DeleteAsync(gamePlayer).ConfigureAwait(false); } await GamesTable.DeleteAsync(game).ConfigureAwait(false); } } }
public async Task <List <Game> > GetGames(string playerId) { if (string.IsNullOrEmpty(playerId)) { return(new List <Game>()); } var gamePlayers = await GamePlayersTable.Where(x => x.PlayerId == playerId && x.Hide == false).ToListAsync().ConfigureAwait(false); var games = await GamesTable.ToListAsync().ConfigureAwait(false); var result = new List <Game>(); foreach (var gamePlayer in gamePlayers) { var game = games.FirstOrDefault(x => x.Id == gamePlayer.GameId); if (game != null) { result.Add(game); } } return(result); }
public async Task <List <GamePlayer> > GetGamePlayers(string gameId) { return(await GamePlayersTable.Where(x => x.GameId == gameId).ToListAsync()); }
public async Task <GamePlayer> GetGamePlayer(string gameId, string playerId) { var result = await GamePlayersTable.Where(x => x.GameId == gameId && x.PlayerId == playerId).ToListAsync().ConfigureAwait(false); return(result.FirstOrDefault()); }