Example #1
0
        public async Task <ActionResult> AddQuizQuestions(int id)
        {
            AddQuizQuestionsViewModel viewModel = new AddQuizQuestionsViewModel();

            viewModel.QuizId    = id;
            viewModel.Questions = new List <CreateQuestionViewModel>();
            SetupQuestions(viewModel);

            viewModel.Tags = await GetSearchableTagsAsync();

            return(View(viewModel));
        }
Example #2
0
 private static void SetupQuestions(AddQuizQuestionsViewModel viewModel)
 {
     for (int i = 0; i < 10; i++)
     {
         CreateQuestionViewModel      q       = new CreateQuestionViewModel();
         List <CreateAnswerViewModel> answers = new List <CreateAnswerViewModel>();
         for (int j = 0; j < 4; j++)
         {
             CreateAnswerViewModel a = new CreateAnswerViewModel();
             answers.Add(a);
         }
         q.Answers = answers;
         viewModel.Questions.Add(q);
     }
 }
Example #3
0
        public async Task <ActionResult> AddQuizQuestions(AddQuizQuestionsViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                foreach (var question in viewModel.Questions)
                {
                    var answerContents = question.Answers.Select(x => x.Content).ToList();
                    var result         = await TriviaService.AddQuestionToQuizAsync(
                        viewModel.QuizId,
                        question.Content,
                        question.Points,
                        answerContents.AsReadOnly(),
                        question.CorrectAnswer,
                        question.SelectedTags.AsReadOnly());
                }
            }

            viewModel.Tags = await GetSearchableTagsAsync();

            return(View(viewModel));
        }