Beispiel #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());
        }
        public async Task <CommandResult> DumpExistingFriendshipRequest(Guid profileId, Guid friendId)
        {
            FriendshipRequest friendshipRequest = await _friendshipRequestRepository.GetActiveByCompositeIdAsync(profileId, friendId);

            if (friendshipRequest == null)
            {
                return(CommandResult.Failure("Falha ao baixar solicitação existente", "A solicitação de amizade não foi encontrada no banco de dados."));
            }

            friendshipRequest.Dump();
            if (!friendshipRequest.IsValid)
            {
                return(CommandResult.Failure(friendshipRequest.GetNotifications().ToList()));
            }

            await _friendshipRequestRepository.UpdateAsync(friendshipRequest);

            return(CommandResult.Ok());
        }