Esempio n. 1
0
        private Test GetTest(QuestionViewModel qvm)
        {
            ////Get new TestId by passing studentId, testType to TestService
            Test t;
            Student student = _service.GetStudent(qvm.StudentId);
            if (qvm.TestId == 0)
            {
                t = _service.CreateTest(qvm.TestType, student);
                //testId = t.Id;
            }
            else
            {
                t = _service.GetTest(qvm.TestId);
            }

            return t;
        }
Esempio n. 2
0
 private void SaveAnswer(QuestionViewModel qvm, Question prevQuestion, Test test)
 {
     if (qvm.AnswerValue != null && prevQuestion != null)
     {
         Answer answer = new Answer();
         answer.Value = qvm.AnswerValue;
         //test = service.GetTest(testId);
         _service.SaveAnswer(test, answer, prevQuestion);
     }
 }
Esempio n. 3
0
        public ActionResult Question( QuestionViewModel qvm)
        {
            //if (!ModelState.IsValid)
            //    return View("Error");

            Test test = null;
            Question prevQuestion = null;
            Question nextQuestion = null;

            if (qvm.StudentId == 0)
                return View("Error");

            test = GetTest(qvm);

            //Get current question
            if (qvm.QuestionId > 0)
            {
                prevQuestion = _service.GetQuestion(qvm.QuestionId);
            }

            //Save answer
            SaveAnswer(qvm, prevQuestion, test);

            //Get next question
            nextQuestion = _service.GetNextQuestion(test, prevQuestion);

            //Check if Test is completed -- If not update model values
            if (nextQuestion == null)
            {
                return View("TestComplete");
            }
            else
            {
                qvm.QuestionId = nextQuestion.Id;
                qvm.QuestionValue = nextQuestion.Value;
                qvm.TestId = test.Id;
                ModelState.Remove("QuestionId");
            }

            //Figure out which PartialView to render
            ViewBag.Partial = GetViewName(nextQuestion);
            if (ViewBag.Partial == "Error")
            {
                return View("Error");
            }
            return View(qvm);
        }