|
| 1 | +// <copyright file="CancelWorkflow.cs" company="DocuSign"> |
| 2 | +// Copyright (c) DocuSign. All rights reserved. |
| 3 | +// </copyright> |
| 4 | + |
| 5 | +namespace DocuSign.Maestro.Controllers |
| 6 | +{ |
| 7 | + using DocuSign.CodeExamples; |
| 8 | + using DocuSign.CodeExamples.Common; |
| 9 | + using DocuSign.CodeExamples.Controllers; |
| 10 | + using DocuSign.CodeExamples.Models; |
| 11 | + using DocuSign.Maestro.Client; |
| 12 | + using DocuSign.Maestro.Model; |
| 13 | + using DocuSign.WebForms.Examples; |
| 14 | + using Microsoft.AspNetCore.Mvc; |
| 15 | + using Microsoft.Extensions.Configuration; |
| 16 | + using Newtonsoft.Json; |
| 17 | + |
| 18 | + [Area("Maestro")] |
| 19 | + [Route("mae002")] |
| 20 | + public class CancelWorkflow : EgController |
| 21 | + { |
| 22 | + private IConfiguration configuration; |
| 23 | + |
| 24 | + public CancelWorkflow( |
| 25 | + DsConfiguration config, |
| 26 | + IConfiguration configuration, |
| 27 | + LauncherTexts launcherTexts, |
| 28 | + IRequestItemsService requestItemsService) |
| 29 | + : base(config, launcherTexts, requestItemsService) |
| 30 | + { |
| 31 | + this.configuration = configuration; |
| 32 | + this.CodeExampleText = this.GetExampleText(this.EgName, ExamplesApiType.Maestro); |
| 33 | + this.ViewBag.title = this.CodeExampleText.ExampleName; |
| 34 | + } |
| 35 | + |
| 36 | + public override string EgName => "mae002"; |
| 37 | + |
| 38 | + [MustAuthenticate] |
| 39 | + [HttpGet] |
| 40 | + public override IActionResult Get() |
| 41 | + { |
| 42 | + try |
| 43 | + { |
| 44 | + var actionResult = base.Get(); |
| 45 | + if (this.RequestItemsService.EgName == this.EgName) |
| 46 | + { |
| 47 | + return actionResult; |
| 48 | + } |
| 49 | + |
| 50 | + var accessToken = this.RequestItemsService.User.AccessToken; |
| 51 | + var accountId = this.RequestItemsService.Session.AccountId; |
| 52 | + var docuSignClient = new DocuSignClient(this.RequestItemsService.Session.MaestroApiBasePath); |
| 53 | + docuSignClient.Configuration.DefaultHeader.Add("Authorization", "Bearer " + accessToken); |
| 54 | + bool isInProgressStatus = false; |
| 55 | + if (this.RequestItemsService.InstanceId != null) |
| 56 | + { |
| 57 | + var instance = GetWorkflowService.GetWorkFlowInstance( |
| 58 | + docuSignClient, |
| 59 | + accountId, |
| 60 | + this.RequestItemsService.WorkflowId, |
| 61 | + this.RequestItemsService.InstanceId); |
| 62 | + isInProgressStatus = instance.InstanceState == WorkflowInstanceState.InProgress; |
| 63 | + } |
| 64 | + |
| 65 | + this.ViewBag.WorkflowId = this.RequestItemsService.WorkflowId; |
| 66 | + this.ViewBag.InstanceId = this.RequestItemsService.InstanceId; |
| 67 | + this.ViewBag.IsInProgressStatus = isInProgressStatus; |
| 68 | + |
| 69 | + return this.View("mae002"); |
| 70 | + } |
| 71 | + catch (ApiException apiException) |
| 72 | + { |
| 73 | + this.ViewBag.errorCode = apiException.ErrorCode; |
| 74 | + this.ViewBag.errorMessage = apiException.Message; |
| 75 | + this.ViewBag.SupportingTexts = this.LauncherTexts.ManifestStructure.SupportingTexts; |
| 76 | + |
| 77 | + return this.View("Error"); |
| 78 | + } |
| 79 | + } |
| 80 | + |
| 81 | + [MustAuthenticate] |
| 82 | + [SetViewBag] |
| 83 | + [HttpPost] |
| 84 | + [ValidateAntiForgeryToken] |
| 85 | + public ActionResult CancelFlow() |
| 86 | + { |
| 87 | + try |
| 88 | + { |
| 89 | + var accessToken = this.RequestItemsService.User.AccessToken; |
| 90 | + var accountId = this.RequestItemsService.Session.AccountId; |
| 91 | + //ds-snippet-start:Maestro2Step2 |
| 92 | + var docuSignClient = new DocuSignClient(this.RequestItemsService.Session.MaestroApiBasePath); |
| 93 | + docuSignClient.Configuration.DefaultHeader.Add("Authorization", "Bearer " + accessToken); |
| 94 | + //ds-snippet-end:Maestro2Step2 |
| 95 | + var result = CancelWorkflowService.CancelWorkflow(docuSignClient, accountId, this.RequestItemsService.InstanceId); |
| 96 | + |
| 97 | + this.ViewBag.h1 = this.CodeExampleText.ExampleName; |
| 98 | + this.ViewBag.message = string.Format(this.CodeExampleText.ResultsPageText, this.RequestItemsService.InstanceId); |
| 99 | + this.ViewBag.Locals.Json = JsonConvert.SerializeObject(result, Formatting.Indented); |
| 100 | + |
| 101 | + return this.View("example_done"); |
| 102 | + } |
| 103 | + catch (ApiException apiException) |
| 104 | + { |
| 105 | + this.ViewBag.errorCode = apiException.ErrorCode; |
| 106 | + this.ViewBag.errorMessage = apiException.Message; |
| 107 | + this.ViewBag.SupportingTexts = this.LauncherTexts.ManifestStructure.SupportingTexts; |
| 108 | + |
| 109 | + return this.View("Error"); |
| 110 | + } |
| 111 | + } |
| 112 | + } |
| 113 | +} |
0 commit comments