public virtual PlayerAchievementDetails GetCurrentPlayerAchievementDetails(AchievementId achievementId, ApplicationUser currentUser)
        {
            var achievement = _achievementRetriever.GetAchievement(achievementId);

            var result = new PlayerAchievementDetails
            {
                AchievementId   = achievementId,
                Description     = achievement.Description,
                IconClass       = achievement.IconClass,
                AchievementName = achievement.Name,
                LevelThresholds = achievement.LevelThresholds
            };

            result.NumberOfPlayersWithThisAchievement = _dataContext.GetQueryable <PlayerAchievement>().Count(y => y.AchievementId == achievementId);

            if (currentUser.UserName == AnonymousApplicationUser.USER_NAME_ANONYMOUS)
            {
                return(result);
            }

            var playerForCurrentUser = _playerRetriever.GetPlayerForCurrentUser(currentUser.Id, currentUser.CurrentGamingGroupId);

            if (playerForCurrentUser != null)
            {
                result.PlayerId   = playerForCurrentUser.Id;
                result.PlayerName = playerForCurrentUser.Name;

                var achievementAwarded = achievement.IsAwardedForThisPlayer(playerForCurrentUser.Id);

                result.AchievementLevel = achievementAwarded.LevelAwarded;
                result.PlayerProgress   = achievementAwarded.PlayerProgress;

                SetRelatedEntities(achievement.Group, result, achievementAwarded.RelatedEntities);
            }

            var playerAchievement = _dataContext
                                    .GetQueryable <PlayerAchievement>()
                                    .FirstOrDefault(x => x.AchievementId == achievementId && x.Player.ApplicationUserId == currentUser.Id);

            if (playerAchievement == null)
            {
                return(result);
            }

            result.DateCreated     = playerAchievement.DateCreated;
            result.LastUpdatedDate = playerAchievement.LastUpdatedDate;

            return(result);
        }
Exemplo n.º 2
0
        public virtual PlayerAchievementDetails GetPlayerAchievement(PlayerAchievementQuery playerAchievementQuery)
        {
            var achievementId = playerAchievementQuery.AchievementId;
            var achievement   = _achievementRetriever.GetAchievement(achievementId);

            var result = new PlayerAchievementDetails
            {
                AchievementId   = achievementId,
                Description     = achievement.Description,
                IconClass       = achievement.IconClass,
                AchievementName = achievement.Name,
                LevelThresholds = achievement.LevelThresholds
            };

            result.NumberOfPlayersWithThisAchievement = _dataContext.GetQueryable <PlayerAchievement>().Count(y => y.AchievementId == achievementId);


            Player player;

            if (playerAchievementQuery.PlayerId.HasValue)
            {
                player = _dataContext.FindById <Player>(playerAchievementQuery.PlayerId);
            }
            else
            {
                player = _playerRetriever.GetPlayerForCurrentUser(playerAchievementQuery.ApplicationUserId, playerAchievementQuery.GamingGroupId.Value);
            }

            if (player != null)
            {
                result.PlayerId   = player.Id;
                result.PlayerName = player.Name;

                var achievementAwarded = achievement.IsAwardedForThisPlayer(player.Id);

                result.AchievementLevel = achievementAwarded.LevelAwarded;
                result.PlayerProgress   = achievementAwarded.PlayerProgress;

                SetRelatedEntities(achievement.Group, result, achievementAwarded.RelatedEntities);
            }

            var playerAchievement = _dataContext
                                    .GetQueryable <PlayerAchievement>()
                                    .FirstOrDefault(x => x.AchievementId == achievementId && x.PlayerId == playerAchievementQuery.PlayerId);

            if (playerAchievement == null)
            {
                return(result);
            }

            result.DateCreated     = playerAchievement.DateCreated;
            result.LastUpdatedDate = playerAchievement.LastUpdatedDate;

            return(result);
        }