コード例 #1
0
 //create a simple test
 public static WebResult AddSimpleTest(SimpleTest newtest)
 {
     using (Entities e = new Entities())
     {
         WebResult wb = new WebResult();
         try
         {
             //add new test
             var t = e.tests.Add(TestCasting.TestToDAL(newtest.test));
             //add classes o the new test
             t.classes = ClassCasting.ClassesToDAL(newtest.classes);
             //add questions to the new test
             t.questions = QuestionCasting.QuestionsToDAL(newtest.questions);
             wb.status   = true;
             wb.message  = "succeed";
             wb.value    = TestCasting.TestToDTO(t);
             e.SaveChanges();
             return(wb);
         }
         catch (Exception ex)
         {
             wb.status  = false;
             wb.message = ex.Message;
             return(wb);
         }
     }
 }
コード例 #2
0
        //create generated test
        public static WebResult AddGeneratedTest(GeneratedTest newtest)
        {
            using (Entities e = new Entities())
            {
                WebResult wb = new WebResult();
                try
                {
                    //add new test
                    test t = e.tests.Add(TestCasting.TestToDAL(newtest.test));
                    e.SaveChanges();
                    //add rand questions to the new test
                    List <question> newQuesList = RandQues(t.test_id, t.level, newtest.american,
                                                           newtest.yesNo, newtest.match, newtest.classes.FirstOrDefault().teacher_id, newtest.subCategories);
                    t.classes.AddRange(ClassCasting.ClassesToDAL(newtest.classes));
                    newQuesList.ForEach(q =>
                    {
                        question qq = new question()
                        {
                            question_level = q.question_level,
                            question_id    = q.question_id,
                            question_text  = q.question_text,
                            //// answers = q.answers,
                            // sub_category = q.sub_category,
                            sub_category_id = q.sub_category_id,
                            // tests = q.tests,
                            // type = q.type,
                            type_id = q.type_id
                        };
                        t.questions.Add(qq);
                    });
                    //t.questions.AddRange(newQuesList.ToList());

                    wb.status  = true;
                    wb.message = "succeed";
                    wb.value   = TestCasting.TestToDTO(t);
                    e.SaveChanges();
                    return(wb);
                }
                catch (Exception ex)
                {
                    wb.status  = false;
                    wb.message = ex.Message;
                    return(wb);
                }
            }
        }