Ejemplo n.º 1
0
 public static void UpdateTestQuestions(Question[] questions)
 {
     if (questions == null) return;
     using (var db = new TestSystemEntities())
     {
         foreach (var item in questions)
         {
             db.Questions.Add(item);
             var entry = db.Entry(item);
             entry.State = EntityState.Modified;
         }
         db.SaveChanges();
     }
 }
Ejemplo n.º 2
0
        public static void AddQuestion(int test, Question q)
        {
            using (var db = new TestSystemEntities())
            {
                db.Questions.Add(q);
                var entry = db.Entry(q);
                entry.State = EntityState.Added;
                db.SaveChanges();

                TestQuestion t = new TestQuestion()
                {
                    QuestionId = q.Id,
                    TestId = test
                };
                db.TestQuestions.Add(t);
                db.SaveChanges();
            }
        }
Ejemplo n.º 3
0
        public ActionResult AddQuestion(EditTestViewModel vm)
        {
            Question q = new Question();
            q.Title = vm.AddQuestion.Title;
            q.QuestionType = vm.AddQuestion.QuestionType;
            if (vm.AddQuestion.QuestionType == 2)
            {
                q.CorrectAnswer = vm.AddQuestion.CorrectAnswer;
            }
            else if (vm.AddQuestion.QuestionType == 4)
            {
                q.Answer1 = vm.AddQuestion.Answer1;
                q.Answer2 = vm.AddQuestion.Answer2;
                q.Answer3 = vm.AddQuestion.Answer3;
                q.Answer4 = vm.AddQuestion.Answer4;
                q.CorrectAnswer = vm.AddQuestion.CorrectAnswer;
            }
            q.Points = vm.AddQuestion.Points;

            DB.AddQuestion(vm.Test.Id, q);

            return RedirectToAction("EditTest", new { id = vm.Test.Id });
        }