public CurrentGamesViewModel(int? playerId) : this() { if (playerId != null) { using (IGameDataService dataService = new GameDataService()) { IEnumerable<DB.Match> playingMatches = dataService.GetPlayingMatchesForPlayer(playerId.Value); foreach (var match in playingMatches) { DB.Player opponent = dataService.GetPlayer(match.PlayerOneId == playerId ? match.PlayerTwoId : match.PlayerOneId); DB.Game currentGame = dataService.GetGame(match.CurrentGameId.Value); DB.Player currentPlayer = null; if (currentGame.CurrentPlayerId != null) currentPlayer = dataService.GetPlayer(currentGame.CurrentPlayerId.Value); CurrentGamesViewModel.Game game = new Game(); game.MatchId = match.MatchId; game.OpponentName = opponent.PlayerName; game.PlayerTurn = currentPlayer != null ? currentPlayer.PlayerName : "none"; game.StartDateTime = match.CreateDate; this.Games.Add(game); } } } }
AIGame IGameDataService.CreateAIGame(Player player, Game game, Match match) { AIGame result = this.repository.CreateAIGame(); result.PlayerId = player.PlayerId; result.GameId = game.GameId; if (match != null) result.MatchId = match.MatchId; return result; }