public int GetGradeCount(int grade) { using (VocabularyEntities context = new VocabularyEntities()) { return(context.Words.Count(x => x.Grade == grade)); } }
public Word GetNetxWord(Word currentWord, int userKey) { using (VocabularyEntities context = new VocabularyEntities()) { int wordId = currentWord.WordId; int grade = currentWord.Grade; var stagedList = context.StagedWords .Where(x => x.Word.Grade == grade && x.UserKey == userKey) .Select(x => x.WordId) .ToList(); var list = context.Words .Where(x => x.Grade == grade && x.WordId != wordId) .Where(x => !stagedList.Contains(x.WordId)) .ToList(); Word word = list .OrderBy(x => x.WordId) .FirstOrDefault(); return(word); } }
public User GetByUserId(string id) { using (VocabularyEntities context = new VocabularyEntities()) { return(context.Users.FirstOrDefault(x => x.Id == id)); } }
public User GetByPk(int userKey) { using (VocabularyEntities context = new VocabularyEntities()) { return(context.Users.FirstOrDefault(x => x.UserKey == userKey)); } }
public StagedWord GetByWordId(int userKey, int wordId) { using (VocabularyEntities context = new VocabularyEntities()) { StagedWord word = context.StagedWords .Where(x => x.WordId == wordId && x.UserKey == userKey) .FirstOrDefault(); return(word); } }
public int IncreasePassedCount(int userKey, int wordId) { using (VocabularyEntities context = new VocabularyEntities()) { StagedWord stagedWord = context.StagedWords.FirstOrDefault(x => x.UserKey == userKey && x.WordId == wordId); stagedWord.PassedCount++; context.SaveChanges(); return(stagedWord.PassedCount); } }
public List <Word> GetTestList(int userKey, int grade) { using (VocabularyEntities context = new VocabularyEntities()) { var list = (from x in context.StagedWords where x.UserKey == userKey && x.Word.Grade == grade && x.PassedCount == 0 select new { x.Word, x.PassedCount } ).ToList(); return(list.ConvertAll(x => new Word(x.Word, x.PassedCount))); } }
public void DeleteWordByGrade(int userKey, int grade) { using (VocabularyEntities context = new VocabularyEntities()) { List <StagedWord> list = (from x in context.StagedWords where x.UserKey == userKey && x.Word.Grade == grade select x).ToList(); context.StagedWords.RemoveRange(list); context.SaveChanges(); } }
public List <Word> GetReviewList(int userKey) { using (VocabularyEntities context = new VocabularyEntities()) { var list = (from x in context.StagedWords where x.UserKey == userKey && x.PassedCount < 3 && x.PassedCount > 0 orderby x.PassedCount select new { x.Word, x.PassedCount } ).ToList(); return(list.ConvertAll(x => new Word(x.Word, x.PassedCount))); } }
public LastSelect GetLastSelect(int userKey, int grade) { using (VocabularyEntities context = new VocabularyEntities()) { LastSelect lastSelect = context.LastSelects.FirstOrDefault(x => x.UserKey == userKey && x.Grade == grade); if (lastSelect == null) { lastSelect = new LastSelect { UserKey = userKey, Grade = grade, WordId = context.Words.Where(x => x.Grade == grade).FirstOrDefault().WordId }; context.LastSelects.Add(lastSelect); context.SaveChanges(); return(lastSelect); } return(lastSelect); } }
public void SetLastSelect(int userKey, int grade, int wordId) { using (VocabularyEntities context = new VocabularyEntities()) { LastSelect lastSelect = context.LastSelects.FirstOrDefault(x => x.UserKey == userKey && x.Grade == grade); if (lastSelect != null) { lastSelect.WordId = wordId; } else { lastSelect = new LastSelect(); lastSelect.UserKey = userKey; lastSelect.Grade = grade; lastSelect.WordId = wordId; context.LastSelects.Add(lastSelect); } context.SaveChanges(); } }