Пример #1
0
        // GET: Word

        public ActionResult Index()
        {
            _learnedWords = new LearnedWordXmlSource(ServerPath.MapUserVocabularyPath(UserName));
            var words = _learnedWords.GetAll().ToList();

            return(View(words));
        }
Пример #2
0
        public ActionResult AddToLearned(int fileId, string[] words)
        {
            _documentWords = new WordInfoXmlSource(ServerPath.MapDocumentPath(fileId.ToString()));
            _learnedWords  = new LearnedWordXmlSource(ServerPath.MapUserVocabularyPath(UserName));
            foreach (string word in words)
            {
                var wordInfo = _documentWords.Get(w => w.WordString == word);
                wordInfo.Status = Models.WordStatus.Learned;

                LearnWord outValue;
                bool      learned = _learnedWords.IsLearned(word, out outValue);

                if (learned)
                {
                    outValue.Documents.Add(fileId);
                }
                else
                {
                    outValue = new LearnWord {
                        WordString = word, Documents = new List <int> {
                            fileId
                        }
                    };
                    _learnedWords.Add(outValue);
                }
            }

            _documentWords.Save();
            _learnedWords.Save();
            return(RedirectToAction("Load", "Home", new { fileId = fileId }));
        }
Пример #3
0
        private List <WordInfo> ConvertToWordInfo(IEnumerable <KeyValuePair <string, int> > wordsCount)
        {
            LearnWord kostyl;

            LearnedWordXmlSource source =
                new LearnedWordXmlSource(ServerPath.MapUserVocabularyPath(User.Identity.Name));
            List <WordInfo> wordsInfo = new List <WordInfo>(wordsCount.Count());

            foreach (var pair in wordsCount)
            {
                WordInfo word = new WordInfo {
                    WordString = pair.Key, Count = pair.Value
                };

                if (source.IsLearned(pair.Key, out kostyl))
                {
                    word.Status = WordStatus.Learned;
                }
                else
                {
                    word.Status = WordStatus.NotLearned;
                }

                wordsInfo.Add(word);
            }
            return(wordsInfo);
        }