public async Task <CommandResult> Handle(CancelFriendshipRequestCommand request, CancellationToken cancellationToken) { FriendshipRequest friendshipRequest = await _friendshipRequestRepository.GetByIdAsync(request.FriendshipRequestId); if (friendshipRequest == null || !friendshipRequest.IsRequester(_currentProfileId)) { return(FailureDueToFriendshipNotFound()); } friendshipRequest.Cancel(); if (!friendshipRequest.IsValid) { return(FailureDueToEntityStateInconsistency(friendshipRequest)); } await _friendshipRequestRepository.UpdateAsync(friendshipRequest); return(await CommitAndPublishDefaultAsync()); }