Esempio n. 1
0
        public virtual int AddCourseInfo(IudicoCourseInfo courseInfo)
        {
            var db = this.GetDbContext();

            CoursesInfo ci = new CoursesInfo
            {
                CourseId = courseInfo.Id,
                OverallMaxScore = (float)courseInfo.OverallMaxScore
            };

            db.CoursesInfo.InsertOnSubmit(ci);
            db.SubmitChanges();

            foreach (IudicoNodeInfo nodeInfo in courseInfo.NodesInfo)
            {
                NodesInfo ni = new NodesInfo
                {
                    CourseId = courseInfo.Id,
                    NodeId = nodeInfo.Id,
                    MaxScore = (float)nodeInfo.MaxScore
                };

                db.NodesInfo.InsertOnSubmit(ni);
                db.SubmitChanges();

                foreach (IudicoQuestionInfo questionInfo in nodeInfo.QuestionsInfo)
                {
                    QuestionsInfo qi = new QuestionsInfo
                    {
                        NodeId = nodeInfo.Id,
                        Text = questionInfo.QuestionText,
                        MaxScore = (float)questionInfo.MaxScore
                    };

                    switch (questionInfo.Type)
                    {
                        case IudicoQuestionType.IudicoSimple:
                            qi.Type = 1;
                            break;

                        case IudicoQuestionType.IudicoChoice:
                            qi.Type = 2;
                            break;

                        case IudicoQuestionType.IudicoCompile:
                            qi.Type = 3;
                            break;
                    }

                    db.QuestionsInfo.InsertOnSubmit(qi);
                    db.SubmitChanges();

                    switch (questionInfo.Type)
                    {
                        case IudicoQuestionType.IudicoSimple:
                            SimpleQuestion sq = new SimpleQuestion
                            {
                                QuestionId = qi.Id,
                                CorrectAnswer = (questionInfo as IudicoSimpleQuestion).CorrectAnswer
                            };

                            db.SimpleQuestions.InsertOnSubmit(sq);
                            db.SubmitChanges();
                            break;

                        case IudicoQuestionType.IudicoChoice:
                            ChoiceQuestionsCorrectChoice cqcc = new ChoiceQuestionsCorrectChoice
                            {
                                QuestionId = qi.Id,
                                CorrectChoice = (questionInfo as IudicoChoiceQuestion).CorrectChoice
                            };

                            db.ChoiceQuestionsCorrectChoices.InsertOnSubmit(cqcc);
                            db.SubmitChanges();

                            foreach (var option in (questionInfo as IudicoChoiceQuestion).Options)
                            {
                                ChoiceQuestionsOption cqo = new ChoiceQuestionsOption
                                {
                                    QuestionId = qi.Id,
                                    Option = option.Item1,
                                    Description = option.Item2
                                };

                                db.ChoiceQuestionsOptions.InsertOnSubmit(cqo);
                                db.SubmitChanges();
                            }
                            break;

                        case IudicoQuestionType.IudicoCompile:
                            for (int i = 0; i < (questionInfo as IudicoCompiledTest).NumberOfTests; ++i)
                            {
                                CompiledTestQuestion ctq = new CompiledTestQuestion
                                {
                                    QuestionId = qi.Id,
                                    TestNumber = i,
                                    TestInput = (questionInfo as IudicoCompiledTest).TestInputs[i].Item2,
                                    TestOutput = (questionInfo as IudicoCompiledTest).TestOutputs[i].Item2
                                };


                                db.CompiledTestQuestions.InsertOnSubmit(ctq);
                                db.SubmitChanges();
                            }
                            break;
                    }
                }
            }

            return courseInfo.Id;
        }
Esempio n. 2
0
 partial void UpdateSimpleQuestion(SimpleQuestion instance);
Esempio n. 3
0
 partial void DeleteSimpleQuestion(SimpleQuestion instance);
Esempio n. 4
0
 partial void InsertSimpleQuestion(SimpleQuestion instance);