private static void AddInactivePlayerSuffix(PlayerWithNemesis playerWithNemesis)
 {
     if (!playerWithNemesis.PlayerActive)
     {
         playerWithNemesis.PlayerName += " (INACTIVE)";
     }
 }
        public PlayerWithNemesisViewModel Build(PlayerWithNemesis playerWithNemesis, ApplicationUser currentUser)
        {
            ValidatePlayerNotNull(playerWithNemesis);

            AddInactivePlayerSuffix(playerWithNemesis);

            var totalGamesPlayed = playerWithNemesis.GamesLost + playerWithNemesis.GamesWon;
            var model = new PlayerWithNemesisViewModel
            {
                PlayerId = playerWithNemesis.PlayerId,
                PlayerName = playerWithNemesis.PlayerName,
                PlayerActive = playerWithNemesis.PlayerActive,
                PlayerRegistered = playerWithNemesis.PlayerRegistered,
                UserCanEdit = (currentUser != null && playerWithNemesis.GamingGroupId == currentUser.CurrentGamingGroupId),
                NemesisPlayerId = playerWithNemesis.NemesisPlayerId,
                NemesisPlayerName = playerWithNemesis.NemesisPlayerName,
                PreviousNemesisPlayerId = playerWithNemesis.PreviousNemesisPlayerId,
                PreviousNemesisPlayerName = playerWithNemesis.PreviousNemesisPlayerName,
                NumberOfPlayedGames = totalGamesPlayed,
                OverallWinPercentage = WinPercentageCalculator.CalculateWinPercentage(playerWithNemesis.GamesWon, playerWithNemesis.GamesLost),
                NemePointsSummary = new NemePointsSummaryViewModel(playerWithNemesis.NemePointsSummary),
                TotalChampionedGames = playerWithNemesis.TotalChampionedGames,
                AveragePointsPerGame = totalGamesPlayed > 0 ? (float)playerWithNemesis.NemePointsSummary.TotalPoints / (float)totalGamesPlayed : 0,
                AchievementsPerLevel = playerWithNemesis.AchievementsPerLevel
            };

            return model;
        }
 private static void ValidatePlayerNotNull(PlayerWithNemesis player)
 {
     if (player == null)
     {
         throw new ArgumentNullException("player");
     }
 }
Exemple #4
0
        public void SetUp()
        {
            builder = new PlayerWithNemesisViewModelBuilder();
            playerWithNemesis = new PlayerWithNemesis
            {
                PlayerId = 100,
                PlayerRegistered = true,
                PlayerName = "player name",
                PlayerActive = true,
                NemesisPlayerId = 300,
                NemesisPlayerName = "nemesis player name",
                PreviousNemesisPlayerId = 400,
                PreviousNemesisPlayerName = "previous nemesis player name",
                GamingGroupId = gamingGroupId,
                GamesLost = 1,
                GamesWon = 1,
                NemePointsSummary = new NemePointsSummary(1, 4, 5),
                TotalChampionedGames = 1
            };

            currentUser = new ApplicationUser
            {
                CurrentGamingGroupId = gamingGroupId
            };
        }