private async Task SendCommentLikedEventAsync(Guid likingUserId, Domain.AggregatesModel.CommentAggregate.Comment comment) { var post = await _postRepository.GetByIdAsync(comment.PostId); var @event = new CommentLikedEvent { LikingUserId = likingUserId, PostUserId = post.UserId, PostId = comment.PostId, CommentUserId = comment.UserId, CommentId = comment.Id, CommentText = comment.Text }; await SendEvent(@event); }
public async Task <int> Handle(UserReplyPostCommand request, CancellationToken cancellationToken) { var comment = new Domain.AggregatesModel.CommentAggregate.Comment(); comment.ReplyPost(request.Text, request.PostId, request.RepliedUserId); _commentRepository.Add(comment); if (await _commentRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken)) { var post = await _postRepository.GetByIdAsync(request.PostId); await SendPostRepliedEventAsync(post, request.RepliedUserId, request.Text); //返回帖子评论的总数量 return(post.CommentCount); } throw new ApplicationException("操作失败"); }
public async Task <int> Handle(ReplyCommentCommand request, CancellationToken cancellationToken) { var userId = Guid.Parse(_httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value); var parentComment = await _commentRepository.GetByIdAsync(request.CommentId); var comment = new Domain.AggregatesModel.CommentAggregate.Comment(); comment.ReplyComment(request.Text, parentComment.PostId, request.CommentId, userId); _commentRepository.Add(comment); if (await _commentRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken)) { await SendCommentRepliedEventAsync(userId, parentComment.UserId, comment.Id, parentComment.PostId, request.Text); //返回帖子评论的总数量 var post = await _postRepository.GetByIdAsync(parentComment.PostId); return(post.CommentCount); } throw new ApplicationException("操作失败"); }