Пример #1
0
        /// <summary>
        /// Sets up the view model to contain a list of quizzes and whether or not the current user has completed those quizzes
        /// </summary>
        /// <param name="currentUserId"></param>
        /// <param name="viewModel"></param>
        /// <returns></returns>
        private async Task SetupQuizzesOnDashboardAsync(string currentUserId, DashboardViewModel viewModel)
        {
            var quizzes = await TriviaService.GetQuizzesAsync();

            viewModel.Quizzes = Mapper.Map <IReadOnlyCollection <Quiz>, IReadOnlyCollection <QuizOverviewViewModel> >(quizzes);
            var completedQuizzes = await TriviaService.GetCompletedQuizzesByUserAsync(currentUserId);

            foreach (var quiz in viewModel.Quizzes)
            {
                if (completedQuizzes.Any(q => q.Key == quiz.Id))
                {
                    quiz.IsComplete = true;
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Alters the viewmodel's list of quizzes to indicate if the quiz has already been completed by the currently logged in user
        /// </summary>
        /// <param name="currentUserId"></param>
        /// <param name="viewModel"></param>
        /// <returns></returns>
        private async Task SetQuizzesCompletedByCurrentUser(string currentUserId, TriviaDashboardViewModel viewModel)
        {
            var completedQuizzes = await TriviaService.GetCompletedQuizzesByUserAsync(currentUserId);

            foreach (var quiz in viewModel.NewQuizzes)
            {
                if (completedQuizzes.Any(q => q.Key == quiz.Id))
                {
                    quiz.IsComplete = true;
                }
            }

            foreach (var quizCollection in viewModel.DailyQuizzes.Values)
            {
                foreach (var quiz in quizCollection)
                {
                    if (completedQuizzes.Any(q => q.Key == quiz.Id))
                    {
                        quiz.IsComplete = true;
                    }
                }
            }
        }
Пример #3
0
        private async Task <int> GetAchievedAmountForUserAsync(string userId, int milestoneTypeId)
        {
            int amount = 0;

            // get the number of questions answered correctly
            if (milestoneTypeId == (int)MilestoneTypeValues.QuestionsAnsweredCorrectly)
            {
                amount = await TriviaService.GetQuestionsAnsweredCorrectlyCountAsync(userId);
            }
            // get the number of quizzes completed successfully
            else if (milestoneTypeId == (int)MilestoneTypeValues.QuizzesCompletedSuccessfully)
            {
                var completedQuizzes = await TriviaService.GetCompletedQuizzesByUserAsync(userId);

                amount = completedQuizzes.Count;
            }
            // get the number of gifts sent
            else if (milestoneTypeId == (int)MilestoneTypeValues.GiftSent)
            {
                amount = await ProfileService.GetSentGiftCountForUserAsync(userId);
            }
            // get the number of gifts purchased
            else if (milestoneTypeId == (int)MilestoneTypeValues.GiftsPurchased)
            {
                amount = await ProfileService.GetPurchasedItemCountForUserAsync(userId, (int)StoreItemTypeValues.Gift);
            }
            // get the number of points obtained
            else if (milestoneTypeId == (int)MilestoneTypeValues.PointsObtained)
            {
                amount = await ProfileService.GetLifetimePointsForUserAsync(userId);
            }
            // get the number of profiles reviewed
            else if (milestoneTypeId == (int)MilestoneTypeValues.ProfileReviewsWritten)
            {
                amount = await ProfileService.GetReviewsWrittenCountByUserAsync(userId);
            }
            // get the number of images uploaded
            else if (milestoneTypeId == (int)MilestoneTypeValues.ProfileImagesUploaded)
            {
                amount = await ProfileService.GetImagesUploadedCountByUserAsync(userId);
            }
            // get the number of titles purchased
            else if (milestoneTypeId == (int)MilestoneTypeValues.TitlesPurchased)
            {
                amount = await ProfileService.GetPurchasedItemCountForUserAsync(userId, (int)StoreItemTypeValues.Title);
            }
            // get the number of tags awarded
            else if (milestoneTypeId == (int)MilestoneTypeValues.TagsAwarded)
            {
                amount = await ProfileService.GetTagAwardCountForUserAsync(userId);
            }
            else if (milestoneTypeId == (int)MilestoneTypeValues.Trekkie ||
                     milestoneTypeId == (int)MilestoneTypeValues.RebelAlliance ||
                     milestoneTypeId == (int)MilestoneTypeValues.HighWarlord)
            {
                int quizId = 0;
                if (milestoneTypeId == (int)MilestoneTypeValues.Trekkie)
                {
                    quizId = (int)QuizValues.StarTrek_TOS;
                }
                else if (milestoneTypeId == (int)MilestoneTypeValues.RebelAlliance)
                {
                    quizId = (int)QuizValues.StarWarsCharacters;
                }
                else if (milestoneTypeId == (int)MilestoneTypeValues.HighWarlord)
                {
                    quizId = (int)QuizValues.WorldOfWarcraft_HighWarlord;
                }

                bool hasUserCompletedQuiz = await TriviaService.IsQuizCompletedByUserAsync(userId, quizId);

                amount = hasUserCompletedQuiz ? 1 : 0;
            }
            else if (milestoneTypeId == (int)MilestoneTypeValues.GoldMedalist)
            {
                bool hasUserCompletedQuiz1 = await TriviaService.IsQuizCompletedByUserAsync(userId, (int)QuizValues.SummerOlympics);

                bool hasUserCompletedQuiz2 = await TriviaService.IsQuizCompletedByUserAsync(userId, (int)QuizValues.WinterOlympics);

                amount = (hasUserCompletedQuiz1 && hasUserCompletedQuiz2) ? 1 : 0;
            }
            else if (milestoneTypeId == (int)MilestoneTypeValues.HighFive)
            {
                int daysAgo = 1;
                int countOfQuizzesCompletedInLastDay = await TriviaService.CountOfQuizzesCompletedAsync(userId, daysAgo);

                amount = countOfQuizzesCompletedInLastDay >= 5 ? 1 : 0;
            }
            else if (milestoneTypeId == (int)MilestoneTypeValues.MultiTalented)
            {
                // if the categories "touched" by the user (completed a quiz in that category) are equal to the number of total categories, achievement!
                int quizCategoryCount = (await TriviaService.GetQuizCategoriesAsync()).Count;
                int quizCategoriesTouchedByUserCount = await TriviaService.GetQuizCategoriesTouchedByUserCountAsync(userId);

                amount = quizCategoriesTouchedByUserCount == quizCategoryCount ? 1 : 0;
            }
            else if (milestoneTypeId == (int)MilestoneTypeValues.FriendlyExchange)
            {
                TimeSpan duration = TimeSpan.FromMinutes(30);

                // has anyone even sent us something in the last 30 minutes?
                var giftsSentToCurrentUser = await ProfileService.GetGiftsSentToUserAsync(userId, duration);

                // someone sent us something in the last 30 minutes! yay, we're popular
                if (giftsSentToCurrentUser.Count > 0)
                {
                    // these are the user ids of the people who sent us gifts
                    var userIdsForGiftsSent = giftsSentToCurrentUser.Select(x => x.FromUserId);

                    // now check if we sent any gifts to anyone who sent us a gift in the last 30 minutes
                    var giftsSentToUsers = await ProfileService.GetGiftsSentToUsersFromUserAsync(userId, userIdsForGiftsSent, duration);

                    // we sent someone a gift that sent us a gift in the last 30 minutes
                    if (giftsSentToUsers.Count > 0)
                    {
                        amount = 1;
                    }
                }
            }
            else if (milestoneTypeId == (int)MilestoneTypeValues.ReferralSignUps)
            {
                int count = await UserService.GetReferralsRedeemedCountAsync(userId);

                amount = count >= 3 ? 1 : 0;
            }

            return(amount);
        }