Skip to content

Commit 4c6f4a0

Browse files
committed
Added DoWork methods
1 parent fea60e5 commit 4c6f4a0

15 files changed

+610
-367
lines changed

eg-03-csharp-auth-code-grant-core/Controllers/Eg001EmbeddedSigningController.cs

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,32 +24,20 @@ public Eg001EmbeddedSigningController(DSConfiguration config, IRequestItemsServi
2424
ViewBag.title = "Embedded Signing Ceremony";
2525
}
2626

27-
[HttpPost]
28-
public IActionResult Create(string signerEmail, string signerName)
27+
private string DoWork(string signerEmail, string signerName,
28+
string accessToken, string basePath, string accountId)
2929
{
3030
// Data for this method
3131
// signerEmail
3232
// signerName
33+
// accessToken
34+
// basePath
35+
// accountId
36+
3337
// dsPingUrl -- class global
3438
// signerClientId -- class global
3539
// dsReturnUrl -- class global
36-
var accessToken = RequestItemsService.User.AccessToken;
37-
var basePath = RequestItemsService.Session.BasePath + "/restapi";
38-
var accountId = RequestItemsService.Session.AccountId;
3940

40-
41-
// Check the token with minimal buffer time.
42-
bool tokenOk = CheckToken(3);
43-
if (!tokenOk)
44-
{
45-
// We could store the parameters of the requested operation
46-
// so it could be restarted automatically.
47-
// But since it should be rare to have a token issue here,
48-
// we'll make the user re-enter the form data after
49-
// authentication.
50-
RequestItemsService.EgName = EgName;
51-
return Redirect("/ds/mustAuthenticate");
52-
}
5341
// Step 1. Create the envelope definition
5442
EnvelopeDefinition envelope = MakeEnvelope(signerEmail, signerName);
5543

@@ -72,7 +60,8 @@ public IActionResult Create(string signerEmail, string signerName)
7260
// Don't use an iFrame!
7361
// State can be stored/recovered using the framework's session or a
7462
// query parameter on the returnUrl (see the makeRecipientViewRequest method)
75-
return Redirect(results1.Url);
63+
string redirectUrl = results1.Url;
64+
return redirectUrl;
7665
}
7766

7867
private RecipientViewRequest MakeRecipientViewRequest(string signerEmail, string signerName)
@@ -188,5 +177,36 @@ private EnvelopeDefinition MakeEnvelope(string signerEmail, string signerName)
188177
}
189178

190179
public override string EgName => "eg001";
180+
181+
[HttpPost]
182+
public IActionResult Create(string signerEmail, string signerName)
183+
{
184+
// Data for this method
185+
// signerEmail
186+
// signerName
187+
// dsPingUrl -- class global
188+
// signerClientId -- class global
189+
// dsReturnUrl -- class global
190+
string accessToken = RequestItemsService.User.AccessToken;
191+
string basePath = RequestItemsService.Session.BasePath + "/restapi";
192+
string accountId = RequestItemsService.Session.AccountId;
193+
194+
// Check the token with minimal buffer time.
195+
bool tokenOk = CheckToken(3);
196+
if (!tokenOk)
197+
{
198+
// We could store the parameters of the requested operation
199+
// so it could be restarted automatically.
200+
// But since it should be rare to have a token issue here,
201+
// we'll make the user re-enter the form data after
202+
// authentication.
203+
RequestItemsService.EgName = EgName;
204+
return Redirect("/ds/mustAuthenticate");
205+
}
206+
207+
string redirectUrl = DoWork(signerEmail, signerName, accessToken, basePath, accountId);
208+
// Redirect the user to the Signing Ceremony
209+
return Redirect(redirectUrl);
210+
}
191211
}
192212
}

eg-03-csharp-auth-code-grant-core/Controllers/Eg002SigningViaEmailController.cs

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Threading.Tasks;
53
using DocuSign.eSign.Api;
64
using DocuSign.eSign.Model;
75
using eg_03_csharp_auth_code_grant_core.Models;
86
using Microsoft.AspNetCore.Mvc;
9-
using System.IO;
107
using System.Text;
118
using DocuSign.eSign.Client;
129

@@ -23,28 +20,6 @@ public Eg002SigningViaEmailController(DSConfiguration config, IRequestItemsServi
2320

2421
public override string EgName => "eg002";
2522

26-
[HttpPost]
27-
public IActionResult Create(string signerEmail, string signerName, string ccEmail, string ccName)
28-
{
29-
// Check the token with minimal buffer time.
30-
bool tokenOk = CheckToken(3);
31-
if (!tokenOk)
32-
{
33-
// We could store the parameters of the requested operation
34-
// so it could be restarted automatically.
35-
// But since it should be rare to have a token issue here,
36-
// we'll make the user re-enter the form data after
37-
// authentication.
38-
RequestItemsService.EgName = EgName;
39-
return Redirect("/ds/mustAuthenticate");
40-
}
41-
EnvelopeSummary results = DoWork(signerEmail, signerName, ccEmail, ccName);
42-
ViewBag.h1 = "Envelope sent";
43-
ViewBag.message = "The envelope has been created and sent!<br />Envelope ID " + results.EnvelopeId + ".";
44-
//return results;
45-
return View("example_done");
46-
}
47-
4823
public EnvelopeSummary DoWork(string signerEmail, string signerName, string ccEmail, string ccName)
4924
{
5025
// Data for this method
@@ -215,5 +190,26 @@ private byte[] document1(string signerEmail, string signerName, string ccEmail,
215190
" </html>"
216191
);
217192
}
193+
194+
[HttpPost]
195+
public IActionResult Create(string signerEmail, string signerName, string ccEmail, string ccName)
196+
{
197+
// Check the token with minimal buffer time.
198+
bool tokenOk = CheckToken(3);
199+
if (!tokenOk)
200+
{
201+
// We could store the parameters of the requested operation
202+
// so it could be restarted automatically.
203+
// But since it should be rare to have a token issue here,
204+
// we'll make the user re-enter the form data after
205+
// authentication.
206+
RequestItemsService.EgName = EgName;
207+
return Redirect("/ds/mustAuthenticate");
208+
}
209+
EnvelopeSummary results = DoWork(signerEmail, signerName, ccEmail, ccName);
210+
ViewBag.h1 = "Envelope sent";
211+
ViewBag.message = "The envelope has been created and sent!<br />Envelope ID " + results.EnvelopeId + ".";
212+
return View("example_done");
213+
}
218214
}
219215
}

eg-03-csharp-auth-code-grant-core/Controllers/Eg003ListEnvelopesController.cs

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,30 @@ public Eg003ListEnvelopesController(DSConfiguration config, IRequestItemsService
2323

2424
public override string EgName => "eg003";
2525

26+
private EnvelopesInformation DoWork(string accessToken, string basePath, string accountId)
27+
{
28+
// Data for this method
29+
// accessToken
30+
// basePath
31+
// accountId
32+
33+
var config = new Configuration(new ApiClient(basePath));
34+
config.AddDefaultHeader("Authorization", "Bearer " + accessToken);
35+
EnvelopesApi envelopesApi = new EnvelopesApi(config);
36+
ListStatusChangesOptions options = new ListStatusChangesOptions();
37+
options.fromDate = DateTime.Now.AddDays(-30).ToString("yyyy/MM/dd");
38+
// Call the API method:
39+
EnvelopesInformation results = envelopesApi.ListStatusChanges(accountId, options);
40+
return results;
41+
}
42+
2643
[HttpPost]
2744
public IActionResult Create(string signerEmail, string signerName)
2845
{
2946
// Data for this method
30-
var accessToken = RequestItemsService.User.AccessToken;
31-
var basePath = RequestItemsService.Session.BasePath + "/restapi";
32-
var accountId = RequestItemsService.Session.AccountId;
47+
string accessToken = RequestItemsService.User.AccessToken;
48+
string basePath = RequestItemsService.Session.BasePath + "/restapi";
49+
string accountId = RequestItemsService.Session.AccountId;
3350

3451
// Check the token with minimal buffer time.
3552
bool tokenOk = CheckToken(3);
@@ -43,14 +60,10 @@ public IActionResult Create(string signerEmail, string signerName)
4360
RequestItemsService.EgName = EgName;
4461
return Redirect("/ds/mustAuthenticate");
4562
}
46-
var config = new Configuration(new ApiClient(basePath));
47-
config.AddDefaultHeader("Authorization", "Bearer " + accessToken);
48-
EnvelopesApi envelopesApi = new EnvelopesApi(config);
49-
ListStatusChangesOptions options = new ListStatusChangesOptions();
50-
options.fromDate = DateTime.Now.AddDays(-30).ToString("yyyy/MM/dd");
51-
// Call the API method:
52-
EnvelopesInformation results = envelopesApi.ListStatusChanges(accountId, options);
53-
63+
64+
// Call the worker
65+
EnvelopesInformation results = DoWork(accessToken, basePath, accountId);
66+
// Process results
5467
ViewBag.h1 = "List envelopes results";
5568
ViewBag.message = "Results from the Envelopes::listStatusChanges method:";
5669
ViewBag.Locals.Json = JsonConvert.SerializeObject(results,Formatting.Indented);

eg-03-csharp-auth-code-grant-core/Controllers/Eg004EnvelopeInfoController.cs

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Threading.Tasks;
5-
using DocuSign.eSign.Api;
1+
using DocuSign.eSign.Api;
62
using DocuSign.eSign.Client;
3+
using DocuSign.eSign.Model;
74
using eg_03_csharp_auth_code_grant_core.Models;
85
using Microsoft.AspNetCore.Mvc;
96
using Newtonsoft.Json;
@@ -21,6 +18,25 @@ public Eg004EnvelopeInfoController(DSConfiguration config, IRequestItemsService
2118

2219
public override string EgName => "eg004";
2320

21+
private Envelope DoWork(string accessToken, string basePath, string accountId,
22+
string envelopeId)
23+
{
24+
// Data for this method
25+
// accessToken
26+
// basePath
27+
// accountId
28+
// envelopeId
29+
30+
var config = new Configuration(new ApiClient(basePath));
31+
config.AddDefaultHeader("Authorization", "Bearer " + accessToken);
32+
EnvelopesApi envelopesApi = new EnvelopesApi(config);
33+
ViewBag.h1 = "Get envelope status results";
34+
ViewBag.message = "Results from the Envelopes::get method:";
35+
Envelope results = envelopesApi.GetEnvelope(accountId, envelopeId);
36+
return results;
37+
}
38+
39+
2440
[HttpPost]
2541
public IActionResult Create(string signerEmail, string signerName)
2642
{
@@ -42,14 +58,12 @@ public IActionResult Create(string signerEmail, string signerName)
4258
RequestItemsService.EgName = EgName;
4359
return Redirect("/ds/mustAuthenticate");
4460
}
45-
var config = new Configuration(new ApiClient(basePath));
46-
config.AddDefaultHeader("Authorization", "Bearer " + accessToken);
47-
EnvelopesApi envelopesApi = new EnvelopesApi(config);
61+
62+
Envelope results = DoWork(accessToken, basePath, accountId, envelopeId);
63+
4864
ViewBag.h1 = "Get envelope status results";
4965
ViewBag.message = "Results from the Envelopes::get method:";
50-
DocuSign.eSign.Model.Envelope results = envelopesApi.GetEnvelope(accountId, envelopeId);
5166
ViewBag.Locals.Json = JsonConvert.SerializeObject(results, Formatting.Indented);
52-
5367
return View("example_done");
5468
}
5569
}

eg-03-csharp-auth-code-grant-core/Controllers/Eg005EnvelopeRecipientsController.cs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using DocuSign.eSign.Api;
22
using DocuSign.eSign.Client;
3+
using DocuSign.eSign.Model;
34
using eg_03_csharp_auth_code_grant_core.Models;
45
using Microsoft.AspNetCore.Mvc;
56
using Newtonsoft.Json;
@@ -17,6 +18,24 @@ public Eg005EnvelopeRecipientsController(DSConfiguration config, IRequestItemsSe
1718

1819
public override string EgName => "eg005";
1920

21+
private Recipients DoWork(string accessToken, string basePath, string accountId,
22+
string envelopeId)
23+
{
24+
// Data for this method
25+
// accessToken
26+
// basePath
27+
// accountId
28+
// envelopeId
29+
var config = new Configuration(new ApiClient(basePath));
30+
config.AddDefaultHeader("Authorization", "Bearer " + accessToken);
31+
EnvelopesApi envelopesApi = new EnvelopesApi(config);
32+
ViewBag.h1 = "List envelope recipients result";
33+
ViewBag.message = "Results from the EnvelopeRecipients::list method:";
34+
Recipients results = envelopesApi.ListRecipients(accountId, envelopeId);
35+
return results;
36+
}
37+
38+
2039
[HttpPost]
2140
public IActionResult Create(string signerEmail, string signerName)
2241
{
@@ -37,14 +56,8 @@ public IActionResult Create(string signerEmail, string signerName)
3756
RequestItemsService.EgName = EgName;
3857
return Redirect("/ds/mustAuthenticate");
3958
}
40-
var config = new Configuration(new ApiClient(basePath));
41-
config.AddDefaultHeader("Authorization", "Bearer " + accessToken);
42-
EnvelopesApi envelopesApi = new EnvelopesApi(config);
43-
ViewBag.h1 = "List envelope recipients result";
44-
ViewBag.message = "Results from the EnvelopeRecipients::list method:";
45-
var results = envelopesApi.ListRecipients(accountId, envelopeId);
59+
Recipients results = DoWork(accessToken, basePath, accountId, envelopeId);
4660
ViewBag.Locals.Json = JsonConvert.SerializeObject(results, Formatting.Indented);
47-
4861
return View("example_done");
4962
}
5063
}

0 commit comments

Comments
 (0)