Пример #1
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));
        }
Пример #2
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));
        }