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; }
partial void DeleteNodesInfo(NodesInfo instance);
partial void UpdateNodesInfo(NodesInfo instance);
partial void InsertNodesInfo(NodesInfo instance);
private void detach_NodesInfos(NodesInfo entity) { this.SendPropertyChanging(); entity.Course = null; }
private void attach_NodesInfos(NodesInfo entity) { this.SendPropertyChanging(); entity.Course = this; }