public async Task <bool> Handle(ToggleUserFollowCommand request, CancellationToken cancellationToken)
        {
            var isFollow = false;
            var ur       = await _userRelationRepository.GetAsync(request.FollowerId, request.UserIdToFollow);

            if (ur == null)
            {
                ur = new UserRelation(request.FollowerId, request.UserIdToFollow);
                ur.Follow();
                _userRelationRepository.Add(ur);
                isFollow = true;
            }
            else
            {
                if (ur.Followed)
                {
                    ur.UnFollow();
                }
                else
                {
                    isFollow = true;
                    ur.Follow();
                }
            }

            var result = await _userRelationRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken);

            if (result)
            {
                if (isFollow)
                {
                    await SendUserFollowedEventAsync(request.FollowerId, request.UserIdToFollow);
                }
                else
                {
                    await SendUserUnFollowedEventAsync(request.FollowerId, request.UserIdToFollow);
                }

                // 返回被关注者是否关注了我
                ur = await _userRelationRepository.GetAsync(request.UserIdToFollow, request.FollowerId);

                return(ur?.Followed ?? false);
            }

            throw new ApplicationException("操作失败");
        }
        public async Task <bool> Handle(FollowEachOtherCommand request, CancellationToken cancellationToken)
        {
            var anotherUserId = await _userRepository.GetUserIdByCodeAsync(request.InvitingUserCode);

            if (anotherUserId != null)
            {
                var userId    = Guid.Parse(request.UserId);
                var relation1 = new UserRelation(userId, anotherUserId.Value);
                var relation2 = new UserRelation(anotherUserId.Value, userId);

                relation1.Follow();
                relation2.Follow();

                _userRelationRepository.Add(relation1);
                _userRelationRepository.Add(relation2);

                return(await _userRelationRepository.UnitOfWork.SaveEntitiesAsync());
            }

            return(false);
        }