Esempio n. 1
0
        protected override long ExecuteWorkImplementation()
        {
            var         now = DateTime.UtcNow;
            TextComment parentTextComment = null;

            if (m_newComment.ParentCommentId != null)
            {
                parentTextComment = m_resourceRepository.FindById <TextComment>(m_newComment.ParentCommentId);
                if (parentTextComment.ParentComment != null)
                {
                    throw new MainServiceException(MainServiceErrorCode.CommentsToSecondLevel, "Only comments to second level are allowed");
                }
                m_newComment.TextReferenceId = parentTextComment.TextReferenceId; // Subcomments must have the same TextReferenceId as parent
            }

            var user         = m_resourceRepository.Load <User>(m_userId);
            var resourceText = m_resourceRepository.Load <Resource>(m_textId);
            var newComment   = new TextComment
            {
                CreateTime      = now,
                CreatedByUser   = user,
                ParentComment   = parentTextComment,
                ResourceText    = resourceText,
                Text            = m_newComment.Text,
                TextReferenceId = m_newComment.TextReferenceId
            };
            var resultId = (long)m_resourceRepository.Create(newComment);

            return(resultId);
        }
Esempio n. 2
0
        public void RemoveResource(long resourceId)
        {
            var resource      = m_resourceRepository.FindById <Resource>(resourceId);
            var pageResource  = m_resourceRepository.GetLatestResourceVersion <PageResource>(resourceId);
            var trackResource = m_resourceRepository.GetLatestResourceVersion <TrackResource>(resourceId);

            resource.IsRemoved = true;
            m_resourceRepository.Update(resource);

            if (pageResource != null)
            {
                var textResourceVersion = m_resourceRepository.GetLatestPageText(resourceId);
                TryRemoveResource(textResourceVersion);

                var imageResourceVersion = m_resourceRepository.GetLatestPageImage(resourceId);
                TryRemoveResource(imageResourceVersion);

                var chapterResourcesVersion = m_resourceRepository.GetLatestChaptersByPages(new[] { resourceId });
                TryRemoveResources(chapterResourcesVersion);
            }

            if (trackResource != null)
            {
                var audioResourceVersion = m_resourceRepository.GetAudioRecordingsByTrack(resourceId);
                TryRemoveResources(audioResourceVersion);
            }
        }
Esempio n. 3
0
        protected override void ExecuteWorkImplementation()
        {
            var textType      = m_mapper.Map <TextTypeEnum>(m_resourceGroupData.TextType);
            var resourceGroup = m_resourceRepository.FindById <NamedResourceGroup>(m_resourceGroupId);

            resourceGroup.Name     = m_resourceGroupData.Name;
            resourceGroup.TextType = textType;

            m_resourceRepository.Update(resourceGroup);
        }
Esempio n. 4
0
        protected override void ExecuteWorkImplementation()
        {
            var now     = DateTime.UtcNow;
            var comment = m_resourceRepository.FindById <TextComment>(m_commentId);

            OwnershipHelper.CheckItemOwnership(comment.CreatedByUser.Id, m_userId);

            comment.Text         = m_data.Text;
            comment.LastEditTime = now;
            comment.EditCount    = comment.EditCount + 1 ?? 1;

            m_resourceRepository.Update(comment);
        }
        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());
        }
Esempio n. 6
0
 public ResourceDTO FindById(int id, string user)
 {
     return((from r in _rRepo.FindById(id, user)
             select new ResourceDTO
     {
         Id = r.Id,
         Author = r.Author,
         Title = r.Title,
         DateCreated = r.DateCreated,
         LastUpdated = r.LastUpdated,
         ImageUrl = r.ImageUrl,
         Link = r.Link,
         Comments = (from c in r.Comments
                     select new CommentDTO
         {
             Id = c.Id,
             Location = c.Location,
             Text = c.Text,
             ResourceId = r.Id
         }).ToList()
     }).FirstOrDefault());
 }
Esempio n. 7
0
        protected override void ExecuteWorkImplementation()
        {
            var dbComment = m_resourceRepository.FindById <TextComment>(m_commentId);

            DeleteCommentsHierarchy(dbComment);
        }