示例#1
0
        public ActionResult SelectQuestions(AddSimpleManualTestViewModel 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 AddSimpleManualTestViewModel
            {
                Rate           = model.Rate,
                Title          = model.Title,
                Time           = model.Time,
                TopicQuestions = topics.ToList()
                                 .ConvertAll(x => new TopicQuestionsManualViewModel
                {
                    Name          = x.Name,
                    Id            = x.Id,
                    OpenQuestions = x.OpenQuestions.ToList().ConvertAll(q => new SelectOpenQuestionViewModel {
                        Question = q
                    }),
                    CloseQuestions = x.CloseQuestions.ToList().ConvertAll(r => new SelectCloseQuestionViewModel {
                        Question = r
                    })
                })
            };

            return(View(viewModel));
        }
示例#2
0
        public ActionResult AddSimpleTest(AddSimpleManualTestViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var teacher = this.userService.GetTeacherByAppUserId(this.User.Identity.GetUserId());
            var testId  = this.manualTestService.Add(new ManualTest
            {
                Rate      = model.Rate,
                TeacherId = teacher.Id,
                Title     = model.Title,
                Time      = model.Time
            });

            if (model.TopicQuestions != null)
            {
                foreach (var item in model.TopicQuestions)
                {
                    if (item.CloseQuestions != null)
                    {
                        foreach (var q in item.CloseQuestions)
                        {
                            if (q.IsSelected)
                            {
                                this.manualTestService.AddCloseQuestion(q.Question.Id, testId);
                            }
                        }
                    }
                    if (item.OpenQuestions != null)
                    {
                        foreach (var q in item.OpenQuestions)
                        {
                            if (q.IsSelected)
                            {
                                this.manualTestService.AddOpenQuestion(q.Question.Id, testId);
                            }
                        }
                    }
                }
            }
            return(Redirect("/ManualTest/Tests"));
        }