//TODO this should be in its own class or just in AutoMapperConfiguration internal virtual PlayedGame TransformNewlyCompletedGameIntoPlayedGame( SaveableGameBase savedGame, int gamingGroupId, string applicationUserId, List<PlayerGameResult> playerGameResults) { var winnerType = WinnerTypes.PlayerWin; if (playerGameResults.All(x => x.GameRank == 1)) { winnerType = WinnerTypes.TeamWin; } else if (playerGameResults.All(x => x.GameRank > 1)) { winnerType = WinnerTypes.TeamLoss; } var numberOfPlayers = savedGame.PlayerRanks.Count; var playedGame = new PlayedGame { GameDefinitionId = savedGame.GameDefinitionId, NumberOfPlayers = numberOfPlayers, WinnerType = winnerType, PlayerGameResults = playerGameResults, DatePlayed = savedGame.DatePlayed, GamingGroupId = gamingGroupId, Notes = savedGame.Notes, CreatedByApplicationUserId = applicationUserId }; return playedGame; }
internal virtual List<PlayerGameResult> MakePlayerGameResults( SaveableGameBase savedGame, int? boardGameGeekGameDefinitionId) { BoardGameGeekGameDefinition boardGameGeekGameDefinition = null; if (boardGameGeekGameDefinitionId.HasValue) { boardGameGeekGameDefinition = _dataContext.FindById<BoardGameGeekGameDefinition>(boardGameGeekGameDefinitionId.Value); } var pointsDictionary = _pointsCalculator.CalculatePoints(savedGame.PlayerRanks, boardGameGeekGameDefinition); var playerGameResults = savedGame.PlayerRanks .Select(playerRank => { var pointsScorecard = pointsDictionary[playerRank.PlayerId]; return new PlayerGameResult { PlayerId = playerRank.PlayerId, GameRank = playerRank.GameRank, NemeStatsPointsAwarded = pointsScorecard.BasePoints, GameDurationBonusPoints = pointsScorecard.GameDurationBonusPoints, GameWeightBonusPoints = pointsScorecard.GameWeightBonusPoints, PointsScored = playerRank.PointsScored }; }) .ToList(); return playerGameResults; }