public ActionResult AddQuestion(int id) { if (this.autoTestForSolvingService.CountTestWithId(id) == 0) { var teacher = this.userService.GetTeacherByAppUserId(this.User.Identity.GetUserId()); var topics = this.topicService.GetForTeacher(teacher.Id); var test = this.automaticTestService.GetById(id); var viewModel = new AddQuestionToAutoTest { Topics = topics.ToList() .ConvertAll(x => new TopicQuestionsAutomaticViewModel { Name = x.Name, Id = x.Id }), TestId = id }; foreach (var item in viewModel.Topics) { var questions = topics.Where(x => x.Id == item.Id).First().CloseQuestions.Where(y => test.CloseQuestions.Select(q => q.Id).Contains(y.Id) == false); item.CloseQuestions = questions.ToList().ConvertAll(r => new SelectCloseQuestionViewModel { Question = r }); } return(View(viewModel)); } TempData["DeQErrors"] = Common.SomeoneUserThisTestNoQ; return(Redirect("/AutomaticTest/Show/" + id)); }
public ActionResult AddQuestion(AddQuestionToAutoTest model) { if (!ModelState.IsValid) { return(View(model)); } foreach (var topic in model.Topics) { foreach (var question in topic.CloseQuestions) { if (question.IsSelected) { automaticTestService.AddCloseQuestion(question.Question.Id, model.TestId); } } } return(Redirect("/AutomaticTest/Show/" + model.TestId)); }