示例#1
0
        public Liking UndoLikeComment(ICommentable entity, MongoObjectId commentId, MongoObjectId parentCommentId)
        {
            Comment comment, parentComment = null;

            if (parentCommentId != null)
            {
                parentComment = GetComment(entity, parentCommentId);
                comment       = parentComment.Comments.Where(c => c.Id == commentId).SingleOrDefault();
            }
            else
            {
                comment = GetComment(entity, commentId);
            }

            if (!comment.SupportingUserIds.Contains(CurrentUser.Id))
            {
                return(null);
            }

            comment.SupportingUserIds.Remove(CurrentUser.Id);

            UpdateEntity(entity);
            var command = new CommentUnlikedCommand
            {
                ObjectId     = entity.Id,
                CommentId    = commentId,
                EntryType    = entity.EntryType,
                UserObjectId = CurrentUser.Id
            };

            bus.Send(command);

            return(GetCommentViewFromComment(entity.Id, comment, parentCommentId, entity.EntryType).Liking);
        }
示例#2
0
        public CommentView ShowComment(ICommentable entity, string commentId, string parentId)
        {
            Comment comment = GetComment(entity, commentId, parentId);

            comment.IsHidden = false;
            UpdateEntity(entity);
            return(GetCommentViewWithComments(entity, comment, parentId));
        }
示例#3
0
        private CommentView GetCommentViewWithComments(ICommentable entity, Comment comment, string parentId = null)
        {
            var commentView = GetCommentViewFromComment(entity.Id, comment, parentId, entity.EntryType,
                                                        entity.GetRelatedVersionNumber(comment.RelatedVersionId));

            foreach (var cComment in comment.Comments.OrderBy(c => c.Date))
            {
                var cCommentView = GetCommentViewFromComment(entity.Id, cComment, comment.Id, entity.EntryType);
                commentView.Comments.Add(cCommentView);
            }

            return(commentView);
        }
示例#4
0
        public CommentView LikeComment(ICommentable entity, MongoObjectId commentId, MongoObjectId parentCommentId)
        {
            Comment comment = GetComment(entity, commentId, parentCommentId);

            if (comment == null || comment.SupportingUserIds.Contains(CurrentUser.Id))
            {
                return(null);
            }

            comment.SupportingUserIds.Add(CurrentUser.Id);

            UpdateEntity(entity);

            return(GetCommentViewFromComment(entity.Id, comment, parentCommentId, entity.EntryType));
        }
示例#5
0
        public virtual CommentView AddNewComment(ICommentable entity, ForAgainst forAgainst, string text, EmbedModel embed, MongoObjectId versionId = null)
        {
            if (CurrentUser.RequireUniqueAuthentication && !CurrentUser.IsUnique)
            {
                throw new UserNotUniqueException();
            }

            if (entity.Id == CurrentUser.Id)
            {
                forAgainst = ForAgainst.Neutral;
            }

            entity.LastNumber++;
            var comment = new Comment
            {
                Date               = DateTime.Now,
                Text               = text,
                UserFullName       = CurrentUser.FullName,
                UserObjectId       = CurrentUser.Id,
                RelatedVersionId   = versionId,
                PositiveOrNegative = forAgainst,
                Number             = entity.LastNumber.ToString() + "."
            };

            if (embed != null && !embed.IsEmpty)
            {
                comment.Embed = new Data.MongoDB.Embed();
                comment.Embed.InjectFrom(embed);

                comment.Embed.Title       = comment.Embed.Title.Sanitize();
                comment.Embed.Description = comment.Embed.Description.Sanitize();
            }
            entity.Comments.Add(comment);
            UpdateEntity(entity);

            var model = GetCommentViewFromComment(entity.Id, comment, null, entity.EntryType,
                                                  entity.GetRelatedVersionNumber(comment.RelatedVersionId));


            model.SubscribeMain = ActionService.Subscribe(entity.Id, CurrentUser.DbId.Value, entity.EntryType);
            model.Subscribe     = ActionService.Subscribe(comment.Id, CurrentUser.DbId.Value);

            return(model);
        }
示例#6
0
        public CommentView AddNewCommentToComment(ICommentable entity, MongoObjectId commentId, string text, EmbedModel embed)
        {
            if (CurrentUser.RequireUniqueAuthentication && !CurrentUser.IsUnique)
            {
                throw new UserNotUniqueException();
            }

            var comment = GetComment(entity, commentId);

            if (comment == null)
            {
                return(null);
            }
            comment.LastNumber++;
            var cComment = new Comment
            {
                Date         = DateTime.Now,
                Text         = text,
                UserFullName = CurrentUser.FullName,
                UserObjectId = CurrentUser.Id,
                Number       = comment.Number + comment.LastNumber
            };

            if (embed != null && !embed.IsEmpty)
            {
                cComment.Embed = new Data.MongoDB.Embed();
                cComment.Embed.InjectFrom(embed);
                cComment.Embed.Title       = cComment.Embed.Title.Sanitize();
                cComment.Embed.Description = cComment.Embed.Description.Sanitize();
            }

            comment.Comments.Add(cComment);

            UpdateEntity(entity);

            var model = GetCommentViewFromComment(entity.Id, cComment, commentId, entity.EntryType,
                                                  entity.GetRelatedVersionNumber(comment.RelatedVersionId));

            model.SubscribeMain = ActionService.Subscribe(entity.Id, CurrentUser.DbId.Value, entity.EntryType);
            model.Subscribe     = ActionService.Subscribe(comment.Id, CurrentUser.DbId.Value);

            return(model);
        }