public IEnumerable <Test> SynchronizeTest() { using (var context = new EnglishQuestionContext()) { return(context.Tests.Include("SubTests").Where(x => string.IsNullOrEmpty(x.Extend1)).ToList()); } }
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 List <ParagraphMeta> GetParagraphMetaOfSection(string testLevel, string questionLevel, string purpose, string section) { using (var context = new EnglishQuestionContext()) { return(context.Paragraphs.Include("Questions.Answers") .Where(x => x.TestLevel.Contains(testLevel) && (x.Section == section) && (x.Level == questionLevel) && (purpose == QuestionPurpose.All.ToString() || x.Purpose == purpose)) .Select(x => new ParagraphMeta() { Id = x.Id, TimeDone = x.Questions.Sum(t => t.TimeDone), AudioFilePath = x.FileInfo, QuestionMeta = x.Questions.Select(y => new QuestionMeta() { Id = y.Id, CanMixAnswers = y.CanMixAnswer, AnswerMeta = y.Answers.Select(z => new AnswerMeta() { Id = z.Id, IsAnswer = z.IsAnswer }).ToList() }).ToList() }).ToList()); } }
public string GetAnswerContent(int answerId) { using (var context = new EnglishQuestionContext()) { return(context.Answers.FirstOrDefault(x => x.Id == answerId)?.Content); } }
public string GetQuestionContent(int questionId) { using (var context = new EnglishQuestionContext()) { return(context.Questions.FirstOrDefault(x => x.Id == questionId)?.Content); } }
public Paragraph GetParagraphById(int id) { using (var context = new EnglishQuestionContext()) { return(context.Paragraphs.Include("Questions.Answers").FirstOrDefault(x => x.Id == id)); } }
public Test GetTest(int id) { using (var context = new EnglishQuestionContext()) { return(context.Tests.Find(id)); } }
public string GetParagraphContent(int paragraphId) { using (var context = new EnglishQuestionContext()) { return(context.Paragraphs.FirstOrDefault(x => x.Id == paragraphId)?.Content); } }
public IEnumerable <B1B2ConfigValue> GetB1B2ConfigValues() { using (var context = new EnglishQuestionContext()) { return(context.B1B2ConfigValues.ToList()); } }
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 Question GetQuestionById(int id) { using (var context = new EnglishQuestionContext()) { return(context.Questions.Include("Answers").FirstOrDefault(x => x.Id == id)); } }
public IEnumerable <ParagraphMeta> GetParagraphMetaByManual(string testLevel, string section) { using (var context = new EnglishQuestionContext()) { return(context.Paragraphs.Include("Questions.Answers") .Where(x => x.TestLevel.Contains(testLevel) && (x.Section == section)) .Select(x => new ParagraphMeta() { Id = x.Id, Title = x.Title, TimeDone = x.Questions.Sum(t => t.TimeDone), AudioFilePath = x.FileInfo, QuestionMeta = x.Questions.Select(y => new QuestionMeta() { Id = y.Id, Content = y.Content, CanMixAnswers = y.CanMixAnswer, AnswerMeta = y.Answers.Select(z => new AnswerMeta() { Id = z.Id, IsAnswer = z.IsAnswer }).ToList() }).ToList() }) .ToList()); } }
public ParagraphMeta GetQuestionMetaOfSection(string testLevel, string questionLevel, string purpose, string section) { using (var context = new EnglishQuestionContext()) { var quetionMeta = context.Questions.Include("Answers") .Where(x => x.TestLevel.Contains(testLevel) && (x.Section == section) && (x.Level == questionLevel) && (purpose == QuestionPurpose.All.ToString() || x.Purpose == purpose)) .Select(x => new QuestionMeta() { Id = x.Id, TimeDone = x.TimeDone, CanMixAnswers = x.CanMixAnswer, AnswerMeta = x.Answers.Select(y => new AnswerMeta() { Id = y.Id, IsAnswer = y.IsAnswer }).ToList() }).ToList(); return(new ParagraphMeta() { Id = 0, QuestionMeta = quetionMeta }); } }
public string GetB1B2ConfigValue(string key) { using (var context = new EnglishQuestionContext()) { return(context.B1B2ConfigValues.FirstOrDefault(x => x.Key == key)?.Value.ToEmpty()); } }
public int SaveSubTest(SubTest subTest) { using (var context = new EnglishQuestionContext()) { context.Entry(subTest).State = EntityState.Modified; return(context.SaveChanges()); } }
public bool CheckExistConfig(string key) { using (var context = new EnglishQuestionContext()) { var config = context.B1B2ConfigValues.FirstOrDefault(x => x.Key == key); return(config != null); } }
public void AddB1B2Config(B1B2ConfigValue configValue) { using (var context = new EnglishQuestionContext()) { context.B1B2ConfigValues.Add(configValue); context.SaveChanges(); } }
public void DeleteB1B2Config(B1B2ConfigValue configValue) { using (var context = new EnglishQuestionContext()) { context.Entry(configValue).State = EntityState.Deleted; context.SaveChanges(); } }
public IEnumerable <Question> GetQuestion(string testLevel, string type) { using (var context = new EnglishQuestionContext()) { return(context.Questions.Include("Answers").Where(x => x.TestLevel.Contains(testLevel) && (x.Type == type) && (x.ParagraphId == DummyParagraph.Id)).ToList()); } }
public IEnumerable <Paragraph> GetParagraph(string testLevel, string type) { using (var context = new EnglishQuestionContext()) { return(context.Paragraphs.Include("Questions.Answers") .Where(x => x.TestLevel.Contains(testLevel) && (x.Type == type)) .ToList()); } }
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 DeleteParagraph(int id) { using (var context = new EnglishQuestionContext()) { var paragraph = context.Paragraphs.Include("Questions.Answers").FirstOrDefault(x => x.Id == id); if (paragraph != null) { DeleteParagraph(paragraph); } } }
public IEnumerable <KeyValueDisplay> GetB1B2Configs() { using (var context = new EnglishQuestionContext()) { return(context.B1B2ConfigValues.Select(x => new KeyValueDisplay() { Key = x.Key, Value = x.Value }).ToList()); } }
public void DeleteQuestion(int id) { using (var context = new EnglishQuestionContext()) { var question = context.Questions.Include("Answers").FirstOrDefault(x => x.Id == id); if (question != null) { DeleteQuestion(question); } } }
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 IEnumerable <Test> LoadTest(string testLevel, bool isChoice) { using (var context = new EnglishQuestionContext()) { var tests = context.Tests.Include("SubTests").Where(x => x.Level == testLevel && x.IsChoice == isChoice).ToList(); foreach (var test in tests) { test.ClassName = GetClass(test.ClassNo).ClassName; yield return(test); } } }
public IEnumerable <Question> SearchQuestion(string testLevel, string section, string content, DateTime from, DateTime to) { using (var context = new EnglishQuestionContext()) { return(context.Questions.Include("Answers") .Where(x => x.TestLevel.Contains(testLevel) && x.Section == section && x.Content.Contains(content) && x.CreatedDate >= from && x.CreatedDate <= to) .ToList()); } }
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(); } }