/// <inheritdoc /> public async Task <Result> Handle(AcceptInvitationCommand request, CancellationToken cancellationToken) { Maybe <Invitation> maybeInvitation = await _invitationRepository.GetByIdAsync(request.InvitationId); if (maybeInvitation.HasNoValue) { return(Result.Failure(DomainErrors.Invitation.NotFound)); } Invitation invitation = maybeInvitation.Value; if (invitation.UserId != _userIdentifierProvider.UserId) { return(Result.Failure(DomainErrors.User.InvalidPermissions)); } Result result = invitation.Accept(_dateTime.UtcNow); if (result.IsFailure) { return(Result.Failure(result.Error)); } await _unitOfWork.SaveChangesAsync(cancellationToken); return(Result.Success()); }
public async Task <DomainValidationResult <Invitation> > AcceptInvitationAsync(Invitation invitation, UserId userId) { if (invitation.UserId != userId) { return(DomainValidationResult <Invitation> .Failure($"The user {userId} can not accept someone else invitation.")); } invitation.Accept(); await _invitationRepository.UnitOfWork.CommitAsync(); return(new DomainValidationResult <Invitation>()); }