コード例 #1
0
ファイル: DB.cs プロジェクト: snaksa/TestSystem
 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();
     }
 }
コード例 #2
0
ファイル: DB.cs プロジェクト: snaksa/TestSystem
        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();
            }
        }
コード例 #3
0
ファイル: AdminController.cs プロジェクト: snaksa/TestSystem
        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 });
        }