Ejemplo n.º 1
0
        public ActionResult SelectQuestions(AddSimpleAutomaticTestViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View("AddSimpleTest", model));
            }
            var teacher   = this.userService.GetTeacherByAppUserId(this.User.Identity.GetUserId());
            var topics    = this.topicService.GetForTeacher(teacher.Id);
            var viewModel = new AddSimpleAutomaticTestViewModel
            {
                Rate           = model.Rate,
                Title          = model.Title,
                TopicQuestions = topics.ToList()
                                 .ConvertAll(x => new TopicQuestionsAutomaticViewModel
                {
                    Name           = x.Name,
                    Id             = x.Id,
                    CloseQuestions = x.CloseQuestions.ToList().ConvertAll(r => new SelectCloseQuestionViewModel {
                        Question = r
                    })
                }),
                Time = model.Time
            };

            return(View(viewModel));
        }
Ejemplo n.º 2
0
        public ActionResult AddSimpleTest(AddSimpleAutomaticTestViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var teacher = this.userService.GetTeacherByAppUserId(this.User.Identity.GetUserId());
            var testId  = this.automaticTestService.Add(new AutomaticTest
            {
                Rate      = model.Rate,
                TeacherId = teacher.Id,
                Title     = model.Title,
                Time      = model.Time
            });

            foreach (var item in model.TopicQuestions)
            {
                foreach (var q in item.CloseQuestions)
                {
                    if (q.IsSelected)
                    {
                        this.automaticTestService.AddCloseQuestion(q.Question.Id, testId);
                    }
                }
            }
            return(Redirect("/AutomaticTest/Tests"));
        }