Ejemplo n.º 1
0
        public async Task <AchievementProgressViewModel> GetAchievementProgressForUserAsync(string userId, int milestoneTypeId)
        {
            var milestones = from milestone in db.Milestones
                             where milestone.MilestoneTypeId == milestoneTypeId
                             orderby milestone.Id
                             select milestone;

            var results = await milestones.ToListAsync();

            AchievementProgressViewModel v = new AchievementProgressViewModel();

            foreach (var milestone in results)
            {
                v.AchievedCount = await GetAchievedAmountForUserAsync(userId, milestoneTypeId);

                v.AchievementIconPath = MilestoneExtensions.GetImagePath(milestone.IconFileName);
                v.RequiredCount       = milestone.AmountRequired;

                // user hasn't reached the required amount yet to go beyond this milestone, break and use this milestone
                if (v.AchievedCount < v.RequiredCount)
                {
                    break;
                }

                //// if the user has not achieved this milestone, break and use it
                //bool hasUserAchievedMilestone = milestone.MilestonesAchieved.Any(x => x.UserId == userId);
                //if (milestone.MilestonesAchieved == null || (milestone.MilestonesAchieved != null && milestone.MilestonesAchieved.Count == 0))
                //{
                //    break;
                //}
            }

            return(v);
        }
Ejemplo n.º 2
0
        public async Task <IReadOnlyCollection <AchievementFeedViewModel> > GetFollowerAchievementsAsync(string userId)
        {
            var achievements = from achievement in db.MilestoneAchievements
                               join favoritedProfiles in db.FavoriteProfiles on achievement.User.Profile.Id equals favoritedProfiles.ProfileId
                               where favoritedProfiles.UserId == userId
                               where achievement.User.IsActive
                               select new AchievementFeedViewModel()
            {
                AchievementIconPath     = achievement.Milestone.IconFileName,
                MilestoneAmountRequired = achievement.Milestone.AmountRequired,
                MilestoneTypeName       = achievement.Milestone.MilestoneType.Name,
                DateAchieved            = achievement.DateAchieved,
                ProfileId            = achievement.User.Profile.Id,
                UserName             = achievement.User.UserName,
                UserProfileImagePath = achievement.User.Profile.UserImage.FileName
            };

            var results = await achievements.ToListAsync();

            foreach (var result in results)
            {
                result.UserProfileImagePath = ProfileExtensions.GetThumbnailImagePath(result.UserProfileImagePath);
                result.AchievementIconPath  = MilestoneExtensions.GetImagePath(result.AchievementIconPath);
            }

            return(results.AsReadOnly());
        }
Ejemplo n.º 3
0
        private async Task <IReadOnlyCollection <AchievementOverviewViewModel> > GetSoloAchievementOverviewsAsync(string userId, IEnumerable <Milestone> soloMilestones)
        {
            var soloMilestoneIds = soloMilestones.Select(x => x.Id).ToList();

            var completedMilestones = await(from achievements in db.MilestoneAchievements
                                            where achievements.UserId == userId
                                            where soloMilestoneIds.Contains(achievements.MilestoneId)
                                            select achievements)
                                      .ToDictionaryAsync(x => x.MilestoneId, x => x.Milestone);

            List <AchievementOverviewViewModel> achievementOverviews = new List <AchievementOverviewViewModel>();

            foreach (var soloMilestone in soloMilestones)
            {
                var achievementOverview = new AchievementOverviewViewModel()
                {
                    AchievementTypeName    = soloMilestone.MilestoneType.Name,
                    AchievementDescription = soloMilestone.MilestoneType.Description,
                    AchievementStatuses    = new List <AchievementStatusViewModel>()
                };

                int achievedCount = HasUserCompletedAchievement(completedMilestones, soloMilestone);

                achievementOverview.AchievementStatuses.Add(new AchievementStatusViewModel()
                {
                    AchievedCount       = achievedCount,
                    RequiredCount       = soloMilestone.AmountRequired,
                    AchievementIconPath = soloMilestone.IconFileName
                });

                achievementOverviews.Add(achievementOverview);
            }

            foreach (var achievementOverview in achievementOverviews)
            {
                // this will always only be a single item for solo achievements
                foreach (var achievementStatus in achievementOverview.AchievementStatuses)
                {
                    achievementStatus.AchievementIconPath = MilestoneExtensions.GetImagePath(achievementStatus.AchievementIconPath);
                }
            }

            return(achievementOverviews.AsReadOnly());
        }
Ejemplo n.º 4
0
        public async Task <IReadOnlyCollection <AchievementUnlockedViewModel> > GetMilestoneDetailsAsync(IReadOnlyCollection <int> milestoneIdsUnlocked)
        {
            var milestones = from milestone in db.Milestones
                             where milestoneIdsUnlocked.Contains(milestone.Id)
                             select new AchievementUnlockedViewModel()
            {
                AchievementName     = milestone.MilestoneType.Name,
                AchievementIconPath = milestone.IconFileName
            };

            var result = await milestones.ToListAsync();

            foreach (var milestone in result)
            {
                milestone.AchievementIconPath = MilestoneExtensions.GetImagePath(milestone.AchievementIconPath);
            }

            return(result.AsReadOnly());
        }
Ejemplo n.º 5
0
        public async Task <IReadOnlyCollection <AchievementCompletedViewModel> > GetCompletedAchievementsAsync(string userId)
        {
            var completedAchievements = from achievements in db.MilestoneAchievements
                                        where achievements.UserId == userId
                                        where achievements.ShowInAchievementShowcase == false
                                        select new AchievementCompletedViewModel()
            {
                MilestoneId        = achievements.MilestoneId,
                MilestoneImagePath = achievements.Milestone.IconFileName,
                MilestoneName      = achievements.Milestone.MilestoneType.Name
            };

            var results = await completedAchievements.ToListAsync();

            foreach (var result in results)
            {
                result.MilestoneImagePath = MilestoneExtensions.GetImagePath(result.MilestoneImagePath);
            }

            return(results);
        }