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 int TotalWordNum() { return(WordDb.Count(x => true)); }