Beispiel #1
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 }));
        }
Beispiel #2
0
 //TODO: change remove logic in XmlSource
 public ActionResult Remove(int fileId, string[] words)
 {
     _documentWords = new WordInfoXmlSource(ServerPath.MapDocumentPath(fileId.ToString()));
     foreach (var word in words)
     {
         var wordToRemove = _documentWords.Get(w => w.WordString == word);
         _documentWords.Remove(wordToRemove);
     }
     _documentWords.Save();
     return(RedirectToAction("Load", "Home", new { fileId = fileId }));
 }
Beispiel #3
0
        public ActionResult Load(int fileId)
        {
            string            filePath = ServerPath.MapDocumentPath(fileId.ToString());
            WordInfoXmlSource source   = new WordInfoXmlSource(filePath);
            var model = new ContentViewModel
            {
                FileId = fileId,
                Words  = source.GetNotLearned()
            };

            return(View("Content", model));
        }
Beispiel #4
0
        public ActionResult Delete(int fileId)
        {
            string userName = User.Identity.Name;

            using (_context = new AppDbContext())
            {
                var file = _context.Files.Find(fileId);
                //var user = _context.Users.First(u => u.UserName == userName);
                //user.Files.Remove(file);
                _context.Files.Remove(file);
                _context.SaveChanges();
            }
            System.IO.File.Delete(ServerPath.MapDocumentPath(fileId.ToString()));
            return(RedirectToAction("DisplayFiles"));
        }
Beispiel #5
0
        public ActionResult Upload(HttpPostedFileBase upload)
        {
            string filePath = SaveFile(upload);
            int    fileId;

            _parser = new TextWorker(new FileProcceserFactory(filePath),
                                     new StopwordsWordValidator(new DefaultWordValidator()),
                                     new Lematizator());

            using (_context = new AppDbContext())
            {
                string      ext  = Path.GetExtension(filePath);
                var         user = _context.Users.First(u => u.UserName == User.Identity.Name);
                Models.File file = new Models.File
                {
                    Extension = _context.Extensions.FirstOrDefault(e => e.ExtensionString == ext),
                    FileName  = Path.GetFileNameWithoutExtension(filePath),
                    UserId    = user.Id
                };

                _context.Files.Add(file);
                _context.SaveChanges();

                fileId = file.FileId;
            }

            WordInfoXmlSource source = new WordInfoXmlSource(ServerPath.MapDocumentPath(fileId.ToString()));

            source.AddRange(ConvertToWordInfo(_parser.CountWords()));
            source.Save();

            var model = new ContentViewModel
            {
                FileId = fileId,
                Words  = source.GetAll().ToList()
            };

            return(View("Content", model));
        }