public bool MoveToNextQuestion()
 {
     if (Test.Questions == null || Test.Questions.Count == 0)
         return false;
     if (currentQuestion == null)
     {
         currentQuestion = Test.Questions.First();
     }
     else
     {
         if (currentQuestionIndex >= Test.Questions.Count() - 1)
         {
             return false;
         }
         currentQuestionIndex++;
         currentQuestion = Test.Questions.ElementAt(currentQuestionIndex);
     }
     return true;
 }
 public ActionResult Edit(QuestionViewModel question)
 {
     QuestionService.Update(question.ToEntity());
     return View(question);
 }
 public ActionResult Create(QuestionViewModel question)
 {
     QuestionService.Create(question.ToEntity());
     return RedirectToAction("Index","Home");
 }
示例#4
0
 public ActionResult UpdateQuestion(QuestionViewModel question)
 {
     var testSubmit = Session["testSubmit"] as TestSubmitViewModel;
     foreach (var optionViewModel in question.Options.Where(optionViewModel => optionViewModel.Value.IsPicked))
     {
         testSubmit.Answers.Add(optionViewModel.Value);
     }
     if (!testSubmit.MoveToNextQuestion())
     {
         return RedirectToAction("FinishTest");
     }
     return PartialView("Quiz",testSubmit.CurrentQuestion);
 }
示例#5
0
 public static QuestionViewModel ToViewModel(this QuestionEntity questionEntity)
 {
     QuestionViewModel questionViewModel = new QuestionViewModel()
     {
         Id = questionEntity.Id,
         Options = new Dictionary<string, OptionViewModel>(),
         TestId = questionEntity.TestId,
         Text = questionEntity.Text
     };
     foreach (var optionEntity in questionEntity.Options)
     {
         questionViewModel.Options.Add(new KeyValuePair<string, OptionViewModel>(
         Guid.NewGuid().ToString("N"),
         optionEntity.ToViewModel()));
     }
     return questionViewModel;
 }