Example #1
0
        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));
        }
Example #2
0
        public bool Append(Word word, Word oldWord)
        {
            List <string> ansList = new List <string>(oldWord.answer.Split('.'));

            ansList.AddRange(word.answer.Split('.'));

            oldWord.meaning += " " + word.meaning;
            oldWord.answer   = String.Join('.', ansList);

            return(WordDb.Update(oldWord));
        }
Example #3
0
        public bool Add(Word word)
        {
            Word tWord = null;

            if ((tWord = Find(word.word)) != null)
            {
                return(Append(word, tWord));
            }

            return(WordDb.Insert(word));
        }
Example #4
0
        public WordList GetAllWords(int num)
        {
            List <Word> words = WordDb.GetList(), ansWords = new List <Word>();

            if (num >= words.Count)
            {
                return(new WordList(words, false));
            }

            Random rand = new Random();

            while (ansWords.Count < num)
            {
                int t = rand.Next(words.Count);

                ansWords.Add(words[t]);
                words.RemoveAt(t);
            }

            return(new WordList(ansWords, false));
        }
Example #5
0
 public List <Word> GetWords()
 {
     return(WordDb.GetList());
 }
Example #6
0
 private Word Find(string word)
 {
     return(WordDb.GetSingle(x => x.word == word));
 }
Example #7
0
 private List <Word> GetTotalWords()
 {
     return(WordDb.GetList());
 }
Example #8
0
 public int TotalWordNum()
 {
     return(WordDb.Count(x => true));
 }