public async Task Handle(BlogCollectedDomainEvent notification, CancellationToken cancellationToken)
        {
            // 当用户收藏了博客文章后,其收藏总数量加1
            UserAsset userAsset = await _userAssetRepository.GetOrCreateAsync(notification.BlogCollect.UserId);

            userAsset.IncreaseCollectBlogCount();
            await _userAssetRepository.InsertOrUpdateAsync(userAsset);
        }
예제 #2
0
        public async Task Handle(BlogPublishedDomainEvent notification, CancellationToken cancellationToken)
        {
            // 当用户发布了博客文章后,博客总数量加1
            UserAsset userAsset = await _userAssetRepository.GetOrCreateAsync(notification.Blog.UserId);

            userAsset.IncreasePublishBlogCount();
            await _userAssetRepository.InsertOrUpdateAsync(userAsset);
        }
        public async Task Handle(BlogCommentedDomainEvent notification, CancellationToken cancellationToken)
        {
            // 检查用户是否已经评论过该博客,如果已评论,则评论博客的总数量不加1
            int count = await _blogCommentRepository.CountAsync(b => b.BlogId == notification.BlogComment.BlogId && b.UserId == notification.BlogComment.UserId);

            if (count > 0)
            {
                return;
            }

            // 当用户评论了博客文章后,其评论博客的总数量加1
            UserAsset userAsset = await _userAssetRepository.GetOrCreateAsync(notification.BlogComment.UserId);

            userAsset.IncreaseCommentBlogCount();
            await _userAssetRepository.InsertOrUpdateAsync(userAsset);
        }
        public async Task Handle(UserPointTaskHappenedDomainEvent notification, CancellationToken cancellationToken)
        {
            UserAsset userAsset = await _userAssetRepository.GetOrCreateAsync(notification.UserId);

            // 实际项目应该采用数据库配置任务对应的积分值
            int point = 0;

            switch (notification.PointTaskType)
            {
            case PointTaskType.Registed:
                point = 100;
                break;

            case PointTaskType.PublishBlog:
                point = 15;
                break;

            default:
                break;
            }
            userAsset.AddPoint(point);
            await _userAssetRepository.InsertOrUpdateAsync(userAsset);
        }