Пример #1
0
 public ActionResult AddQuestion(AddQuestionToManualTest model)
 {
     if (!ModelState.IsValid)
     {
         return(View(model));
     }
     foreach (var topic in model.Topics)
     {
         if (topic.CloseQuestions != null)
         {
             foreach (var cQuestion in topic.CloseQuestions)
             {
                 if (cQuestion.IsSelected)
                 {
                     manualTestService.AddCloseQuestion(cQuestion.Question.Id, model.TestId);
                 }
             }
         }
         if (topic.OpenQuestions != null)
         {
             foreach (var oQuestion in topic.OpenQuestions)
             {
                 if (oQuestion.IsSelected)
                 {
                     manualTestService.AddOpenQuestion(oQuestion.Question.Id, model.TestId);
                 }
             }
         }
     }
     return(Redirect("/ManualTest/Show/" + model.TestId));
 }
Пример #2
0
 public ActionResult AddQuestion(int id)
 {
     if (this.BellongsToCurrentUser(id, this.User.Identity.GetUserId()))
     {
         if (this.manualTestForSolvingService.CountTestWithId(id) == 0)
         {
             var teacher   = this.userService.GetTeacherByAppUserId(this.User.Identity.GetUserId());
             var topics    = this.topicService.GetForTeacher(teacher.Id);
             var test      = this.manualTestService.GetById(id);
             var viewModel = new AddQuestionToManualTest
             {
                 Topics = 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 })
                 }),
                 TestId = id
             };
             foreach (var item in viewModel.Topics)
             {
                 var cQuestions = topics.Where(x => x.Id == item.Id).First().CloseQuestions.Where(y => test.CloseQuestions.Select(q => q.Id).Contains(y.Id) == false);
                 var oQuestions = topics.Where(x => x.Id == item.Id).First().OpenQuestions.Where(y => test.OpenQuestions.Select(q => q.Id).Contains(y.Id) == false);
                 item.CloseQuestions = cQuestions.ToList().ConvertAll(r => new SelectCloseQuestionViewModel {
                     Question = r
                 });
                 item.OpenQuestions = oQuestions.ToList().ConvertAll(r => new SelectOpenQuestionViewModel {
                     Question = r
                 });
             }
             return(View(viewModel));
         }
         TempData["DeQErrors"] = Common.SomeoneUserThisTestNoQ;
         return(Redirect("/ManualTest/Show/" + id));
     }
     return(Redirect("/"));
 }