public void MarkAsPass(WordList wordList) { User user = User.GetUser(); foreach (var word in wordList.words) { User_Word user_word = User_WordDb.GetSingle(x => x.user_id == user.id && x.word == word.word); if (user_word != null) { user_word.learn_time++; User_WordDb.Update(user_word); } else { User_WordDb.Insert(new User_Word { user_id = user.id, word = word.word, learn_time = 1, wrong_time = 0, }); } } if (wordList.isLastWords) { user.current_time++; } user.learned_num += wordList.words.Count; UserDb.Update(user); }
public WordList GetTodoWords(int num) { User user = User.GetUser(); List <Word> todoWordList = new List <Word>(); bool isLastWords; if (user.current_time == 0) { List <Word> totalWordList = GetTotalWords(); Dictionary <string, Word> totalWordDic = new Dictionary <string, Word>(); foreach (var i in totalWordList) { totalWordDic.Add(i.word, i); } List <string> doneWords = User_WordDb.GetList(x => x.user_id == user.id).ConvertAll <string>(x => x.word); foreach (var i in doneWords) { totalWordDic.Remove(i); } Word[] tempArr = new Word[totalWordDic.Count]; totalWordDic.Values.CopyTo(tempArr, 0); todoWordList = new List <Word>(tempArr); //todoWordList = Db.Queryable<User_Word, Word>((x, y) => new object[] { JoinType.Right, x.user_id == user.id && x.word == y.word }).Where((x, y) => x == null).Select((x, y) => y).ToList(); isLastWords = WordDb.AsSugarClient().Queryable <Word>().Count() - doneWords.Count <= num; } else { todoWordList = Db.Queryable <User_Word, Word>((x, y) => new object[] { JoinType.Inner, x.user_id == user.id && x.learn_time <= user.current_time && x.word == y.word }).Select((x, y) => y).ToList(); isLastWords = num + User_WordDb.Count(x => x.user_id == user.id && x.learn_time > user.current_time) >= WordDb.Count(x => true); } List <Word> wordList = new List <Word>(); if (!isLastWords) { Random rand = new Random(); while (wordList.Count < num) { int t = rand.Next(todoWordList.Count); wordList.Add(todoWordList[t]); todoWordList.RemoveAt(t); } } else { wordList = todoWordList; } return(new WordList(wordList, isLastWords)); }
public WordList GetLearnedWords(int num) { User user = User.GetUser(); return(new WordList(User_WordDb.AsSugarClient().Queryable <User_Word, Word>((x, y) => new object[] { JoinType.Inner, x.word == y.word && x.user_id == user.id && x.learn_time > user.current_time }).Select((x, y) => y).ToList(), false)); }