コード例 #1
0
        public Task <ApiResult <ApiPreapprovalResponse> > CreatePreapprovalAsync(ApiPreapprovalRequest preapprovalRequest,
                                                                                 CancellationToken cancellationToken)
        {
            preapprovalRequest.ThrowIfNull(nameof(preapprovalRequest));
            cancellationToken.ThrowIfNull(nameof(cancellationToken));
            preapprovalRequest.Preapproval.ThrowIfNull(nameof(preapprovalRequest.Preapproval));

            var validationResult = _preapprovalRequestValidator.Validate(preapprovalRequest.Preapproval);

            if (!validationResult.IsValid)
            {
                return(validationResult.ToValidationException().ToApiResult <ApiPreapprovalResponse>().ToAwaitable());
            }

            var uri     = new Uri(BaseAddress, PreapprovalUrl);
            var request = preapprovalRequest.ToHttpRequest(HttpMethod.Post, uri);

            return(HttpClient.InvokeAsync <ApiPreapprovalResponse>(request, cancellationToken));
        }
コード例 #2
0
        public Task <ApiResult <ApiPreapprovalResponse> > ChangePreapprovalAsync(int preapprovalId,
                                                                                 ApiPreapprovalRequest preapprovalRequest, CancellationToken cancellationToken)
        {
            preapprovalId.ThrowIfNotCondition(id => id > 0, nameof(preapprovalId));
            preapprovalRequest.ThrowIfNull(nameof(preapprovalRequest));
            cancellationToken.ThrowIfNull(nameof(cancellationToken));
            preapprovalRequest.Preapproval.ThrowIfNull(nameof(preapprovalRequest.Preapproval));

            var validationResult = _preapprovalRequestValidator.Validate(preapprovalRequest.Preapproval);

            if (!validationResult.IsValid)
            {
                return(validationResult.ToValidationException().ToApiResult <ApiPreapprovalResponse>().ToAwaitable());
            }

            var uri     = GetPreapprovalUri(preapprovalId);
            var request = preapprovalRequest.ToHttpRequest(Constants.HttpMethodPatch, uri);

            return(HttpClient.InvokeAsync <ApiPreapprovalResponse>(request, cancellationToken));
        }