public HistoryViewModel(int? playerId) : this() { if (playerId != null) { using (IGameDataService dataService = new GameDataService()) { IEnumerable<DB.Match> playingMatches = dataService.GetAllMatchesForPlayer(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 winningPlayer = null; if (match.WinningPlayerId != null) winningPlayer = dataService.GetPlayer(match.WinningPlayerId.Value); HistoryViewModel.History history = new History(); history.MatchId = match.MatchId; history.OpponentName = opponent.PlayerName; history.Winner = winningPlayer != null ? winningPlayer.PlayerName : "none"; history.EndDate = match.EndDate; history.StartDateTime = match.CreateDate; this.Histories.Add(history); } } } }