Beispiel #1
0
        /// <summary>
        /// Sets up the view model to contain a random question to display to a user
        /// </summary>
        /// <param name="currentUserId"></param>
        /// <param name="viewModel"></param>
        /// <returns></returns>
        private async Task SetupRandomQuestionOnDashboardAsync(string currentUserId, DashboardViewModel viewModel)
        {
            // generate a random question with its answers to view
            var randomQuestion = await TriviaService.GetRandomQuestionAsync(currentUserId, (int)QuestionTypeValues.Random);

            viewModel.RandomQuestion = Mapper.Map <Question, QuestionViewModel>(randomQuestion);
        }
Beispiel #2
0
        /// <summary>
        /// Returns a view model containing a random question of a certain type with its tags and users who have already answered it correctly.
        /// </summary>
        /// <param name="questionTypeId"></param>
        /// <returns></returns>
        private async Task <QuestionViewModel> GetRandomQuestionViewModelAsync(int questionTypeId)
        {
            await SetNotificationsAsync();

            var currentUserId = User.Identity.GetUserId();

            // generate a random question with its answers to view
            var randomQuestion = await TriviaService.GetRandomQuestionAsync(currentUserId, questionTypeId);

            QuestionViewModel viewModel = Mapper.Map <Question, QuestionViewModel>(randomQuestion);

            if (viewModel != null)
            {
                viewModel.QuestionTypeId         = questionTypeId;
                viewModel.UsersAnsweredCorrectly = await GetUsersAnsweredCorrectlyAsync(randomQuestion.Id);

                viewModel.Tags = await GetTagsForQuestionAsync(randomQuestion.Id);

                foreach (var user in viewModel.UsersAnsweredCorrectly)
                {
                    user.IsFavoritedByCurrentUser = await ProfileService.IsProfileFavoritedByUserAsync(user.ProfileId, currentUserId);
                }
            }

            return(viewModel);
        }