예제 #1
0
        public async Task Handle(DeletedPostDomainEvent notification, CancellationToken cancellationToken)
        {
            _logger.LogInformation("----- Handling DeletedPostDomainEvent: at {AppName} - ({@DomainEvent})", Program.AppName, notification);

            var relations = await _userCommentRelationRepository.GetRelationsByCommentIdsAsync(notification.CommentIds);

            relations.ForEach(r => _userCommentRelationRepository.Remove(r));
        }
        public async Task Handle(CommentDeletedDomainEvent notification, CancellationToken cancellationToken)
        {
            _logger.LogInformation("----- Handling CommentDeletedDomainEvent: at {AppName} - ({@DomainEvent})", Program.AppName, notification);

            // 删除“用户-平论”关系
            var relations = await _userCommentRelationRepository.GetRelationsByCommentIdsAsync(notification.CommentIds);

            relations.ForEach(r => _userCommentRelationRepository.Remove(r));

            // 更新帖子的评论数
            var post = await _postRepository.GetByIdAsync(notification.PostId);

            if (post != null)
            {
                post.DecreaseCommentCount(notification.CommentIds.Count, _scoreRewardSettings.CommentPost);
            }
        }