Пример #1
0
        /// <summary>
        /// Get a random question linked to the quiz.
        /// </summary>
        /// <param name="id">The quiz id.</param>
        /// <returns>A random question.</returns>
        private async Task <DisplayGameQuestionModel> GetRandomQuestionFromQuiz(string id)
        {
            Random random = new Random();

            // Database related helpers
            LinkQuizQuestionData linkQuizQuestionData = new LinkQuizQuestionData(_db);
            QuestionData         questionData         = new QuestionData(_db);
            QuestionTypeData     questionTypeData     = new QuestionTypeData(_db);

            // Get Quiz questions and select one randomly
            List <DataLinkQuizQuestionModel> dataLinkQuizQuestionModels = await linkQuizQuestionData.GetLinkedQuestions(id);

            DataLinkQuizQuestionModel randomlySelectedlink     = dataLinkQuizQuestionModels[random.Next(dataLinkQuizQuestionModels.Count)];
            DataQuestionModel         randomlySelectedQuestion = await questionData.GetQuestionById(randomlySelectedlink.QuestionId).ContinueWith((x) => { return(x.Result[0]); });

            // Get Question Type to get the real name
            DataQuestionTypeModel dataQuestionTypeModel = await questionTypeData.GetQuestionTypeById(randomlySelectedQuestion.QuestionTypeId).ContinueWith((x) => { return(x.Result[0]); });

            // Result the translated object
            return(new DisplayGameQuestionModel
            {
                Id = randomlySelectedQuestion.Id,
                Question = randomlySelectedQuestion.Question,
                QuestionType = dataQuestionTypeModel.QuestionType,
            });
        }
Пример #2
0
        /// <summary>
        /// Get the quiz's questions.
        /// </summary>
        /// <param name="id">The quiz's id.</param>
        public async Task OnGetAsync(string id)
        {
            DisplayQuestions = new List <DisplayQuestionModel>();

            // Getting the current quiz
            QuizData quizData       = new QuizData(_db);
            var      dataQuizModels = await quizData.GetQuizById(id);

            DisplayQuizModel = new DisplayQuizModel
            {
                Duration = dataQuizModels[0].Duration,
                Id       = dataQuizModels[0].Id,
                Quiz     = dataQuizModels[0].Quiz,
            };

            // Getting links
            List <DisplayLinkQuizQuestionModel> displayLinkQuizQuestionModels = new List <DisplayLinkQuizQuestionModel>();
            LinkQuizQuestionData             linkQuizQuestionData             = new LinkQuizQuestionData(_db);
            List <DataLinkQuizQuestionModel> dataAccessLinkQuizQuestionModels = await linkQuizQuestionData.GetLinkedQuestions(id);

            foreach (DataLinkQuizQuestionModel dataAccessLinkQuizQuestionModel in dataAccessLinkQuizQuestionModels)
            {
                displayLinkQuizQuestionModels.Add(new DisplayLinkQuizQuestionModel
                {
                    Id         = dataAccessLinkQuizQuestionModel.Id,
                    QuestionId = dataAccessLinkQuizQuestionModel.QuestionId,
                    QuizId     = dataAccessLinkQuizQuestionModel.QuizId,
                });
            }

            DisplayLinks = displayLinkQuizQuestionModels;

            // Gettings questions for the dropdown list
            Questions = new SelectList(await GetQuestions(), "Id", "Question");
        }