Пример #1
0
        public ActionResult Test(TestViewModel vm)
        {
            if (vm.Name == null) vm.Name = "Без име";
            int studentId = DB.AddStudent(vm.Name, vm.Test.Id);

            var test = DB.GetTest(vm.Test.Id);
            int count = 0;
            List<StudentAnswer> answers = new List<StudentAnswer>();

            foreach (var item in test.TestQuestions)
            {
                StudentAnswer ans = new StudentAnswer()
                {
                    Answer = vm.Questions[count],
                    QuestionId = item.QuestionId,
                    StudentId = studentId,
                };
                answers.Add(ans);
                count++;
            }

            DB.AddAnswers(answers);

            TempData["success"] = "1";
            return RedirectToAction("Index");
        }
Пример #2
0
        public ActionResult Test(int id)
        {
            var test = DB.GetTest(id);
            if (test == null) return RedirectToAction("Index");

            string[] q = new string[100];

            TestViewModel vm = new TestViewModel()
            {
                Test = test,
                Questions = q
            };

            return View("SingleTest", vm);
        }