예제 #1
0
        private async Task <List <PostKnn> > ToPostKnn(string[] words, User user)
        {
            var relations = new List <PostKnn>();
            var listWords = words.ToList();

            while (listWords.Count != 0)
            {
                var relation = new PostKnn();
                relation.User = user;
                var globalWord = await _context.GlobalStrings.Where(x => x.Word == listWords[0]).FirstOrDefaultAsync();

                relation.GlobalString = globalWord;
                relation.Count        = listWords.Where(x => x == listWords[0]).Count();
                relations.Add(relation);
                listWords.RemoveAll(x => x == listWords[0]);
            }

            return(relations);
        }
예제 #2
0
        public async Task ManageHistory(string text, User user)
        {
            var stemmedText = await AddToGlobalStrings(text);

            var postknn = new PostKnn();

            var finalUserRelations = await ToPostKnn(text.Split(), user);

            await _context.PostKnns.AddRangeAsync(finalUserRelations);

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (Exception e)
            {
                throw e;
            }
        }