Example #1
0
        private async Task <List <Pknn> > ToPknn(string[] words, Post post)
        {
            var relations = new List <Pknn>();
            var listWords = words.ToList();

            while (listWords.Count != 0)
            {
                var relation = new Pknn();
                relation.Post = post;
                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);
        }
Example #2
0
        public async Task ManagePosts(string text, Post post)
        {
            var stemmedText = await AddToGlobalStrings(text);

            var pknn = new Pknn();

            var finalUserRelations = await ToPknn(text.Split(), post);

            await _context.PKnns.AddRangeAsync(finalUserRelations);

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