Exemple #1
0
        public async Task <IActionResult> SaveAsStudied(int[]  wordId)
        {
            var currentUser = await GetCurrentUserAsync();

            var categoryUser = uow.Categories.Find(i => i.WordCategories.Any(k => k.WordId == wordId[0])).Select(l => l.ApplicationUser).First();


            if (currentUser != categoryUser)
            {
                return(View("AccessDenied"));
            }

            var wordStatistic = new WordStatistic();

            foreach (var id in wordId)
            {
                wordStatistic = uow.WordStatistics.GetAll()
                                .Where(i => i.WordId == id).First();
                wordStatistic.IsStudied = true;
                uow.WordStatistics.Edit(wordStatistic);
            }


            uow.SaveChanges();

            var catId = uow.Categories.GetAll()
                        .Include(i => i.WordCategories)
                        .Where(i => i.WordCategories.Any(k => k.WordId == wordId[0])).Select(k => k.CategoryId).First();


            return(RedirectToAction("List", new { id = catId }));
        }
Exemple #2
0
        private void IncreaseCountOf(string word)
        {
            WordStatistic statistic = RetrieveUniqueStatistic(word);

            statistic.IncreaseCount();
            WordStatistics[word] = statistic;
        }
Exemple #3
0
        public IActionResult Statistic()
        {
            WordStatistic stat = ws.Statistic();

            return(Ok(new {
                count = stat.Count,
                groups = stat.Groups
            }));
        }
Exemple #4
0
        public async Task <IActionResult> Create(Word word, IFormFile file, int id)
        {
            if (ModelState.IsValid)
            {
                if (file != null)
                {
                    var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot\\images", file.FileName);

                    using (var stream = new FileStream(path, FileMode.Create))
                    {
                        await file.CopyToAsync(stream);

                        word.Image = file.FileName;
                    }
                }
                else
                {
                    word.Image = "th.jpg";
                }

                //save category
                var category = uow.Categories.Get(id);
                word.WordCategories = new List <WordCategory>()
                {
                    new WordCategory()
                    {
                        Word = word, Category = category
                    }
                };

                //save word
                uow.Words.Add(word);

                //save word statistics
                var wordStatistic = new WordStatistic()
                {
                    Word      = word,
                    Asked     = 0,
                    IsLearned = false,
                    IsStudied = false,
                    Answered  = 0
                };
                uow.WordStatistics.Add(wordStatistic);


                //save all changes
                uow.SaveChanges();

                return(RedirectToAction("List", new { id = id }));
            }

            return(View(word));
        }
Exemple #5
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        WordStatistic ws = new WordStatistic();
        decimal       i  = 0;

        decimal.TryParse(txtCount.Text, out i);
        ws.HitCount   = i;
        ws.SearchWord = txtSearchWord.Text.Trim();
        if (WordSearchManager.SaveStatistic(ws))
        {
            base.ExecuteJs("msg('成功添加一条新的搜索关键词记录!',true)", false);
        }
        else
        {
            base.ExecuteJs("msg('增加搜索关键词记录时失败!')", false);
        }
    }
        private void HandleFile(MarkdownFile file)
        {
            // normalize text
            RegexOptions options = RegexOptions.Multiline | RegexOptions.IgnoreCase;
            String       text    = file.Content;

            text = Regex.Replace(text, "[^a-zA-Z0-9@äöüÄÖÜ-]+", " ", options);
            text = Regex.Replace(text, "[ ]+", " ", options);
            List <String> words = text.Split(" ").ToList();

            // filter relevant words
            List <String> processedWords = new List <String>();

            foreach (String word in words)
            {
                if (String.IsNullOrEmpty(word) || 3 > word.Length)
                {
                    continue;
                }

                processedWords.Add(word);
            }

            words = processedWords;

            // create map
            foreach (String word in words)
            {
                if (_wordStatistics.ContainsKey(word))
                {
                    _wordStatistics[word].Count++;
                }
                else
                {
                    _wordStatistics[word] = new WordStatistic
                    {
                        Count            = 1
                        , FileReferences = new List <String>()
                        , SimilarWords   = new List <WordStatistic>()
                        , Word           = word
                    };
                }
            }
        }
Exemple #7
0
 public abstract bool SaveStatistic(WordStatistic ws);