public void SaveParagraph(IEnumerable <Paragraph> paragraphs) { using (var context = new EnglishQuestionContext()) { foreach (var paragraph in paragraphs) { if (paragraph.Id > 0) { foreach (var question in paragraph.Questions) { question.ParagraphId = paragraph.Id; question.Paragraph = paragraph; question.Id = 0; context.Entry(question).State = EntityState.Added; foreach (var answer in question.Answers) { context.Entry(answer).State = EntityState.Added; } } context.Entry(paragraph).State = EntityState.Modified; } else { // Add context.Paragraphs.Add(paragraph); } } context.SaveChanges(); } }
public int SaveTest(Test test) { using (var context = new EnglishQuestionContext()) { try { test.EndTestDate = test.TestDate.AddMinutes(test.TotalTime); context.Tests.Add(test); return(context.SaveChanges()); } catch (DbEntityValidationException dbEx) { foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage); } } throw; } } }
public void DeleteB1B2Config(B1B2ConfigValue configValue) { using (var context = new EnglishQuestionContext()) { context.Entry(configValue).State = EntityState.Deleted; context.SaveChanges(); } }
public void AddB1B2Config(B1B2ConfigValue configValue) { using (var context = new EnglishQuestionContext()) { context.B1B2ConfigValues.Add(configValue); context.SaveChanges(); } }
public int SaveSubTest(SubTest subTest) { using (var context = new EnglishQuestionContext()) { context.Entry(subTest).State = EntityState.Modified; return(context.SaveChanges()); } }
public void SynchorizedTests(IEnumerable <Test> tests) { using (var context = new EnglishQuestionContext()) { foreach (var test in tests) { context.Entry(test).State = EntityState.Modified; } context.SaveChanges(); } }
public void DeleteQuestionsOfParagraph(int paragraphId) { using (var context = new EnglishQuestionContext()) { var paragraph = context.Paragraphs.Include("Questions.Answers").FirstOrDefault(x => x.Id == paragraphId); if (paragraph != null) { context.Questions.RemoveRange(paragraph.Questions); context.SaveChanges(); } } }
public void DeleteQuestion(Question question) { using (var context = new EnglishQuestionContext()) { // delete answer foreach (var answer in question.Answers.ToList()) { context.Entry(answer).State = EntityState.Deleted; } // delete question context.Entry(question).State = EntityState.Deleted; context.SaveChanges(); } }
public int SaveQuestion(IEnumerable <Question> questions) { using (var context = new EnglishQuestionContext()) { foreach (var question in questions) { context.Entry(question).State = (question.Id == 0) ? EntityState.Added : EntityState.Modified; foreach (var answer in question.Answers) { context.Entry(answer).State = (answer.Id == 0) ? EntityState.Added : EntityState.Modified; } } return(context.SaveChanges()); } }
public void DeleteParagraph(Paragraph paragraph) { using (var context = new EnglishQuestionContext()) { foreach (var question in paragraph.Questions.ToList()) { foreach (var answer in question.Answers.ToList()) { context.Entry(answer).State = EntityState.Deleted; } context.Entry(question).State = EntityState.Deleted; } context.Entry(paragraph).State = EntityState.Deleted; context.SaveChanges(); } }
public void GenerateTemplateQuestionData() { var questionList = new List <Question>(); for (int i = 1; i <= 100; i++) { var question = new Question() { Content = "Question RQA " + i, Level = QuestionLevel.Normal.ToString(), TestLevel = "A,B,C,B1,B2", Purpose = "All", Section = LevelSection.AR1.ToString(), ParagraphId = 1, Type = "RQA", TimeDone = 2, Title = "Question RQA " + i, Answers = new ObservableCollection <Answer>() { new Answer() { Content = "Answer A", IsAnswer = true }, new Answer() { Content = "Answer B", IsAnswer = false }, new Answer() { Content = "Answer C", IsAnswer = false }, new Answer() { Content = "Answer D", IsAnswer = false }, } }; questionList.Add(question); } for (int i = 1; i <= 100; i++) { var question = new Question() { Content = "Question WQA " + i, Level = QuestionLevel.Normal.ToString(), TestLevel = "A,B,C", Purpose = "All", Section = LevelSection.AR4A.ToString(), ParagraphId = 1, Type = "WQA", TimeDone = 2, Title = "Question WQA " + i, Answers = new ObservableCollection <Answer>() { new Answer() { Content = "Answer A", IsAnswer = true } } }; questionList.Add(question); } for (int i = 1; i <= 100; i++) { var question = new Question() { Content = "Question WPA " + i, Level = QuestionLevel.Normal.ToString(), TestLevel = "A,B,C", Purpose = "All", Section = LevelSection.AR4B.ToString(), ParagraphId = 1, Type = "WQA", TimeDone = 2, Title = "Question WPA " + i, Answers = new ObservableCollection <Answer>() { new Answer() { Content = "Answer A", IsAnswer = true } } }; questionList.Add(question); } using (var context = new EnglishQuestionContext()) { context.Questions.AddRange(questionList); context.SaveChanges(); } }
public void GenerateTemplateParagraphData() { var paragraphList = new List <Paragraph>(); for (int i = 1; i <= 50; i++) { var paragraph = new Paragraph() { Content = "Paragraph " + i, TestLevel = "A,B,C,B1,B2", Section = LevelSection.AR2.ToString(), Purpose = QuestionPurpose.All.ToString(), Level = QuestionLevel.Normal.ToString(), Type = i % 3 == 0 ? "RPQA" : i % 3 == 1 ? "RPA" : "WPA", TimeDone = 10, Title = "Title " + i, Questions = new ObservableCollection <Question>() }; for (int j = 1; j <= 10; j++) { paragraph.Questions.Add(new Question() { Content = paragraph.Content + " Question " + j, Level = paragraph.Level, TestLevel = paragraph.TestLevel, Purpose = "All", Section = "AR2", Type = paragraph.Type, TimeDone = 1, Title = "Question " + j, Answers = new ObservableCollection <Answer>() { new Answer() { Content = "Answer A", IsAnswer = true }, new Answer() { Content = "Answer B", IsAnswer = false }, new Answer() { Content = "Answer C", IsAnswer = false }, new Answer() { Content = "Answer D", IsAnswer = false }, } }); } paragraphList.Add(paragraph); } for (int i = 1; i <= 50; i++) { var paragraph = new Paragraph() { Content = "Paragraph " + i, TestLevel = "A,B,C,B1,B2", Section = LevelSection.AR3.ToString(), Purpose = QuestionPurpose.All.ToString(), Level = QuestionLevel.Normal.ToString(), Type = i % 2 == 0 ? "LQA" : "LQA1", TimeDone = 10, Title = "Title " + i, Questions = new ObservableCollection <Question>() }; for (int j = 1; j <= 10; j++) { paragraph.Questions.Add(new Question() { Content = paragraph.Content + " Question " + i, Level = paragraph.Level, TestLevel = paragraph.TestLevel, Purpose = "All", Section = "AR3", Type = paragraph.Type, TimeDone = 1, Title = "question " + j, Answers = new ObservableCollection <Answer>() { new Answer() { Content = "Answer A", IsAnswer = true }, new Answer() { Content = "Answer B", IsAnswer = false }, new Answer() { Content = "Answer C", IsAnswer = false }, new Answer() { Content = "Answer D", IsAnswer = false }, } }); } paragraphList.Add(paragraph); } using (var context = new EnglishQuestionContext()) { context.Paragraphs.AddRange(paragraphList); context.SaveChanges(); } }