コード例 #1
0
        public async Task <CommandResult> Handle(AcceptFriendshipRequestCommand request, CancellationToken cancellationToken)
        {
            FriendshipRequest friendshipRequest = await _friendshipRequestRepository.GetByIdAsync(request.FriendshipRequestId);

            if (friendshipRequest == null || !friendshipRequest.IsRequested(_currentProfileId))
            {
                return(FailureDueToFriendshipNotFound());
            }

            CommandResult profileServiceResult = await _profileDomainService.MakeFriends(friendshipRequest.RequesterId, friendshipRequest.RequestedId);

            if (!profileServiceResult.Success)
            {
                return(profileServiceResult);
            }

            friendshipRequest.Accept();
            if (!friendshipRequest.IsValid)
            {
                return(FailureDueToEntityStateInconsistency(friendshipRequest));
            }

            await _friendshipRequestRepository.UpdateAsync(friendshipRequest);

            return(await CommitAndPublishDefaultAsync());
        }
コード例 #2
0
        public async Task <CommandResult> Handle(RejectFriendshipRequestCommand request, CancellationToken cancellationToken)
        {
            FriendshipRequest friendshipRequest = await _friendshipRequestRepository.GetByIdAsync(request.FriendshipRequestId);

            if (friendshipRequest == null || !friendshipRequest.IsRequested(_currentProfileId))
            {
                return(FailureDueToFriendshipNotFound());
            }

            friendshipRequest.Reject();
            if (!friendshipRequest.IsValid)
            {
                return(FailureDueToEntityStateInconsistency(friendshipRequest));
            }

            await _friendshipRequestRepository.UpdateAsync(friendshipRequest);

            return(await CommitAndPublishDefaultAsync());
        }