Beispiel #1
0
        public async Task <IActionResult> Index(DocumentToSignViewModel viewModel, CancellationToken token)
        {
            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }

            var documentId = Guid.NewGuid();

            try
            {
                var bytes = await viewModel.DocumentToSign.ToByteArray();

                var request = new AddDocumentToSigningRequest
                {
                    Doc            = bytes,
                    AdditionalInfo = viewModel.AdditionalInfo,
                    SuccessUrl     = Constants.PublicEndpoint + Url.Action("OnSignSuccess", new { documentId }),
                    FailureUrl     = Constants.PublicEndpoint + Url.Action("OnSignFailure", new { documentId }),
                };

                var signingUrl = await _signingService.AddDocumentToSign(request, token);

                _documentInfoRepository.TryAdd(documentId, signingUrl);

                return(Redirect(signingUrl));
            }
            catch (Exception e)
            {
                ModelState.AddModelError(string.Empty, e.Message);
                return(View(viewModel));
            }
        }
        /// <summary>
        /// AddDocumentToSigning call
        /// </summary>
        public virtual AddDocumentToSigningResponse AddDocumentToSigning(
            byte[] document,
            string urlSuccess,
            string urlFailed,
            string additionalInfo,
            out FaultModel fault)
        {
            if (document == null)
            {
                throw new ArgumentNullException("document");
            }
            if (string.IsNullOrEmpty(urlSuccess))
            {
                throw new ArgumentNullException("urlSuccess");
            }
            if (string.IsNullOrEmpty(urlFailed))
            {
                throw new ArgumentNullException("urlFailed");
            }
            if (string.IsNullOrEmpty(additionalInfo))
            {
                throw new ArgumentNullException("additionalInfo");
            }

            fault = null;

            // request
            var request =
                new AddDocumentToSigningRequest()
            {
                Doc            = document,
                SuccessUrl     = urlSuccess,
                FailureUrl     = urlFailed,
                AdditionalInfo = additionalInfo
            };

            // call ePUAP service and parse the response
            var response = WSSecurityRequest <AddDocumentToSigningRequest, AddDocumentToSigningResponse, AddDocumentToSigningResponseHandler>(
                this.ServiceUri,
                request,
                out fault);

            // parsed response
            return(response);
        }