4
4
5
5
namespace DocuSign . CodeExamples . Controllers
6
6
{
7
+ using System ;
7
8
using System . Linq ;
8
9
using System . Threading . Tasks ;
9
10
using DocuSign . CodeExamples . Common ;
@@ -17,6 +18,8 @@ namespace DocuSign.CodeExamples.Controllers
17
18
[ Route ( "mae001" ) ]
18
19
public class Mae001TriggerWorkflowController : EgController
19
20
{
21
+ private const string WorkflowName = "Example workflow - send invite to signer" ;
22
+
20
23
public Mae001TriggerWorkflowController ( DsConfiguration dsConfig ,
21
24
LauncherTexts launcherTexts ,
22
25
IRequestItemsService requestItemsService )
@@ -28,6 +31,96 @@ public Mae001TriggerWorkflowController(DsConfiguration dsConfig,
28
31
29
32
public override string EgName => "mae001" ;
30
33
34
+ [ MustAuthenticate ]
35
+ [ HttpGet ]
36
+ public override IActionResult Get ( )
37
+ {
38
+ var actionResult = base . Get ( ) ;
39
+ if ( this . RequestItemsService . EgName == this . EgName )
40
+ {
41
+ return actionResult ;
42
+ }
43
+
44
+ var basePath = this . RequestItemsService . Session . IamBasePath ;
45
+ var accessToken = this . RequestItemsService . User . AccessToken ;
46
+ var accountId = this . RequestItemsService . Session . AccountId ;
47
+
48
+ try
49
+ {
50
+ if ( this . RequestItemsService . WorkflowId == null )
51
+ {
52
+ WorkflowsListSuccess workflowsList = TriggerMaestroWorkflow . GetMaestroWorkflow (
53
+ basePath ,
54
+ accessToken ,
55
+ accountId ) . GetAwaiter ( ) . GetResult ( ) ;
56
+
57
+ if ( workflowsList . Data != null || workflowsList . Data . Count > 0 )
58
+ {
59
+ var maestroWorkflow = workflowsList . Data . FirstOrDefault ( workflow => workflow . Name == WorkflowName ) ;
60
+
61
+ this . RequestItemsService . WorkflowId = maestroWorkflow ? . Id ;
62
+ }
63
+ }
64
+
65
+ if ( this . RequestItemsService . WorkflowId == null && this . RequestItemsService . TemplateId != null )
66
+ {
67
+ var workflowId = TriggerMaestroWorkflow . CreateWorkflowAsync (
68
+ accessToken ,
69
+ accountId ,
70
+ this . RequestItemsService . TemplateId ,
71
+ this . Config . MaestroWorkflowConfig ) . GetAwaiter ( ) . GetResult ( ) ;
72
+ this . RequestItemsService . WorkflowId = workflowId ;
73
+
74
+ var publishLink = TriggerMaestroWorkflow . PublishWorkflowAsync (
75
+ accountId ,
76
+ workflowId ,
77
+ accessToken ) . GetAwaiter ( ) . GetResult ( ) ;
78
+
79
+ this . RequestItemsService . IsWorkflowPublished = true ;
80
+ this . ViewBag . ConsentLink = this . CodeExampleText . AdditionalPages [ 0 ] . ResultsPageText
81
+ . Replace ( "{0}" , publishLink ) ;
82
+ this . ViewBag . WorkflowId = this . RequestItemsService . WorkflowId ;
83
+ this . ViewBag . TemplateId = this . RequestItemsService . TemplateId ;
84
+
85
+ return this . View ( "publishWorkflow" ) ;
86
+ }
87
+
88
+ if ( this . RequestItemsService . IsWorkflowPublished )
89
+ {
90
+ var publishLink = TriggerMaestroWorkflow . PublishWorkflowAsync (
91
+ accountId ,
92
+ this . RequestItemsService . WorkflowId ,
93
+ accessToken ) . GetAwaiter ( ) . GetResult ( ) ;
94
+
95
+ if ( publishLink != string . Empty )
96
+ {
97
+ this . ViewBag . ConsentLink = this . CodeExampleText . AdditionalPages [ 0 ] . ResultsPageText
98
+ . Replace ( "{0}" , publishLink ) ;
99
+
100
+ this . ViewBag . WorkflowId = this . RequestItemsService . WorkflowId ;
101
+ this . ViewBag . TemplateId = this . RequestItemsService . TemplateId ;
102
+ return this . View ( "publishWorkflow" ) ;
103
+ }
104
+
105
+ this . RequestItemsService . IsWorkflowPublished = false ;
106
+ }
107
+
108
+ this . ViewBag . WorkflowId = this . RequestItemsService . WorkflowId ;
109
+ this . ViewBag . TemplateId = this . RequestItemsService . TemplateId ;
110
+
111
+ return this . View ( "mae001" ) ;
112
+ }
113
+ catch ( Exception apiException )
114
+ {
115
+ this . ViewBag . errorCode = string . Empty ;
116
+ this . ViewBag . errorMessage = apiException . Message ;
117
+ this . ViewBag . SupportingTexts = this . LauncherTexts . ManifestStructure . SupportingTexts ;
118
+ this . ViewBag . SupportMessage = this . CodeExampleText . CustomErrorTexts [ 0 ] . ErrorMessage ;
119
+
120
+ return this . View ( "Error" ) ;
121
+ }
122
+ }
123
+
31
124
[ HttpPost ]
32
125
[ SetViewBag ]
33
126
public async Task < IActionResult > Create (
@@ -53,48 +146,29 @@ public async Task<IActionResult> Create(
53
146
string accessToken = this . RequestItemsService . User . AccessToken ;
54
147
string basePath = this . RequestItemsService . Session . IamBasePath ;
55
148
string accountId = this . RequestItemsService . Session . AccountId ;
149
+ string workflowId = this . RequestItemsService . WorkflowId ;
56
150
57
151
try
58
152
{
59
- WorkflowsListSuccess workflowsList = await TriggerMaestroWorkflow . GetMaestroWorkflow (
153
+ var instance = await TriggerMaestroWorkflow . TriggerWorkflowInstance (
60
154
basePath ,
61
155
accessToken ,
62
- accountId ) ;
156
+ accountId ,
157
+ workflowId ,
158
+ signerEmail ,
159
+ signerName ,
160
+ ccEmail ,
161
+ ccName ,
162
+ instanceName ) ;
63
163
64
- if ( workflowsList . Data != null || workflowsList . Data . Count > 0 )
65
- {
66
- var maestroWorkflow = workflowsList . Data . FirstOrDefault ( workflow =>
67
- workflow . Status == "active" && workflow . Name == "Example workflow - send invite to signer" ) ;
68
-
69
- if ( maestroWorkflow != null )
70
- {
71
- var instance = await TriggerMaestroWorkflow . TriggerWorkflowInstance (
72
- basePath ,
73
- accessToken ,
74
- accountId ,
75
- maestroWorkflow . Id ,
76
- signerEmail ,
77
- signerName ,
78
- ccEmail ,
79
- ccName ,
80
- instanceName ) ;
81
-
82
- this . RequestItemsService . WorkflowId = maestroWorkflow . Id ;
83
- this . RequestItemsService . InstanceId = instance . InstanceId ;
84
-
85
- this . ViewBag . h1 = this . CodeExampleText . ExampleName ;
86
- this . ViewBag . Url = instance . InstanceUrl ;
87
- this . ViewBag . message = string . Format ( this . CodeExampleText . ResultsPageText ) ;
88
-
89
- return this . View ( "embed" ) ;
90
- }
91
- }
164
+ this . RequestItemsService . WorkflowId = workflowId ;
165
+ this . RequestItemsService . InstanceId = instance . InstanceId ;
92
166
93
- this . ViewBag . errorCode = string . Empty ;
94
- this . ViewBag . SupportingTexts = this . LauncherTexts . ManifestStructure . SupportingTexts ;
95
- this . ViewBag . SupportMessage = this . CodeExampleText . CustomErrorTexts [ 0 ] . ErrorMessage ;
167
+ this . ViewBag . h1 = this . CodeExampleText . ExampleName ;
168
+ this . ViewBag . Url = instance . InstanceUrl ;
169
+ this . ViewBag . message = string . Format ( this . CodeExampleText . ResultsPageText ) ;
96
170
97
- return this . View ( "Error " ) ;
171
+ return this . View ( "embed " ) ;
98
172
}
99
173
catch ( APIException exception )
100
174
{
0 commit comments