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 DeleteB1B2Config(B1B2ConfigValue configValue) { using (var context = new EnglishQuestionContext()) { context.Entry(configValue).State = EntityState.Deleted; 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(); } }