コード例 #1
0
        public void AddComment(CommentDTO comment, string currentUser)
        {
            Comment dbComment = new Comment()
            {
                Id         = comment.Id,
                Location   = comment.Location,
                Text       = comment.Text,
                ResourceId = _rRepo.FindById(comment.ResourceId, currentUser).First().Id
            };

            _commentRepo.Add(dbComment);

            //takes text from submitted comment and splits it into an array, then runs it through the English stemmer
            var words = (from s in dbComment.Text.Split(' ')
                         select _stemmer.Stem(s)).ToList();

            //runs stemmed words through FindWords method and picks out the stems
            var dbWords = _wRepo.FindWords(words).ToList();


            //
            words.RemoveAll(w => dbWords.Any(dbw => dbw.Stem == w));
            var newWords = (from w in words
                            select new Word()
            {
                Stem = w
            }).ToList();

            _wRepo.AddWords(newWords);

            dbWords.AddRange(newWords);



            _wRepo.AddWordComments((from w in dbWords
                                    select new WordComment()
            {
                WordId = w.Id,
                CommentId = dbComment.Id
            }).ToList());
        }