Skip to content

Commit fea60e5

Browse files
committed
Added method data comments
1 parent be55160 commit fea60e5

15 files changed

+471
-315
lines changed

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

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
using DocuSign.eSign.Api;
44
using DocuSign.eSign.Client;
55
using DocuSign.eSign.Model;
6-
using eg_03_csharp_auth_code_grant_core.Common;
76
using eg_03_csharp_auth_code_grant_core.Controllers;
87
using eg_03_csharp_auth_code_grant_core.Models;
9-
using Microsoft.AspNetCore.Http;
108
using Microsoft.AspNetCore.Mvc;
119

1210
namespace eg_03_csharp_auth_code_grant_core.Views
@@ -29,6 +27,18 @@ public Eg001EmbeddedSigningController(DSConfiguration config, IRequestItemsServi
2927
[HttpPost]
3028
public IActionResult Create(string signerEmail, string signerName)
3129
{
30+
// Data for this method
31+
// signerEmail
32+
// signerName
33+
// dsPingUrl -- class global
34+
// signerClientId -- class global
35+
// dsReturnUrl -- class global
36+
var accessToken = RequestItemsService.User.AccessToken;
37+
var basePath = RequestItemsService.Session.BasePath + "/restapi";
38+
var accountId = RequestItemsService.Session.AccountId;
39+
40+
41+
// Check the token with minimal buffer time.
3242
bool tokenOk = CheckToken(3);
3343
if (!tokenOk)
3444
{
@@ -40,18 +50,14 @@ public IActionResult Create(string signerEmail, string signerName)
4050
RequestItemsService.EgName = EgName;
4151
return Redirect("/ds/mustAuthenticate");
4252
}
43-
var session = RequestItemsService.Session;
44-
var user = RequestItemsService.User;
4553
// Step 1. Create the envelope definition
4654
EnvelopeDefinition envelope = MakeEnvelope(signerEmail, signerName);
4755

4856
// Step 2. Call DocuSign to create the envelope
49-
var config = new Configuration(new ApiClient(session.BasePath+ "/restapi"));
50-
config.AddDefaultHeader("Authorization", "Bearer "+ user.AccessToken);
57+
var config = new Configuration(new ApiClient(basePath));
58+
config.AddDefaultHeader("Authorization", "Bearer " + accessToken);
5159
EnvelopesApi envelopesApi = new EnvelopesApi(config);
52-
53-
EnvelopeSummary results = envelopesApi.CreateEnvelope(session.AccountId, envelope);
54-
60+
EnvelopeSummary results = envelopesApi.CreateEnvelope(accountId, envelope);
5561
string envelopeId = results.EnvelopeId;
5662

5763
// Save for future use within the example launcher
@@ -60,7 +66,7 @@ public IActionResult Create(string signerEmail, string signerName)
6066
// Step 3. create the recipient view, the Signing Ceremony
6167
RecipientViewRequest viewRequest = MakeRecipientViewRequest(signerEmail, signerName);
6268
// call the CreateRecipientView API
63-
ViewUrl results1 = envelopesApi.CreateRecipientView(session.AccountId, envelopeId, viewRequest);
69+
ViewUrl results1 = envelopesApi.CreateRecipientView(accountId, envelopeId, viewRequest);
6470

6571
// Step 4. Redirect the user to the Signing Ceremony
6672
// Don't use an iFrame!
@@ -71,6 +77,14 @@ public IActionResult Create(string signerEmail, string signerName)
7177

7278
private RecipientViewRequest MakeRecipientViewRequest(string signerEmail, string signerName)
7379
{
80+
// Data for this method
81+
// signerEmail
82+
// signerName
83+
// dsPingUrl -- class global
84+
// signerClientId -- class global
85+
// dsReturnUrl -- class global
86+
87+
7488
RecipientViewRequest viewRequest = new RecipientViewRequest();
7589
// Set the url where you want the recipient to go once they are done signing
7690
// should typically be a callback route somewhere in your app.
@@ -107,8 +121,15 @@ private RecipientViewRequest MakeRecipientViewRequest(string signerEmail, string
107121

108122
private EnvelopeDefinition MakeEnvelope(string signerEmail, string signerName)
109123
{
110-
byte[] buffer = System.IO.File.ReadAllBytes(Config.docPdf);
124+
// Data for this method
125+
// signerEmail
126+
// signerName
127+
// signerClientId -- class global
128+
// Config.docPdf
129+
111130

131+
byte[] buffer = System.IO.File.ReadAllBytes(Config.docPdf);
132+
112133
EnvelopeDefinition envelopeDefinition = new EnvelopeDefinition();
113134
envelopeDefinition.EmailSubject = "Please sign this document";
114135
Document doc1 = new Document();

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

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public Eg002SigningViaEmailController(DSConfiguration config, IRequestItemsServi
2626
[HttpPost]
2727
public IActionResult Create(string signerEmail, string signerName, string ccEmail, string ccName)
2828
{
29+
// Check the token with minimal buffer time.
2930
bool tokenOk = CheckToken(3);
3031
if (!tokenOk)
3132
{
@@ -46,19 +47,36 @@ public IActionResult Create(string signerEmail, string signerName, string ccEmai
4647

4748
public EnvelopeSummary DoWork(string signerEmail, string signerName, string ccEmail, string ccName)
4849
{
49-
var session = RequestItemsService.Session;
50-
var user = RequestItemsService.User;
50+
// Data for this method
51+
// signerEmail
52+
// signerName
53+
// ccEmail
54+
// ccName
55+
var accessToken = RequestItemsService.User.AccessToken;
56+
var basePath = RequestItemsService.Session.BasePath + "/restapi";
57+
var accountId = RequestItemsService.Session.AccountId;
58+
5159
EnvelopeDefinition env = MakeEnvelope(signerEmail, signerName, ccEmail, ccName);
52-
var config = new Configuration(new ApiClient(session.BasePath + "/restapi"));
53-
config.AddDefaultHeader("Authorization", "Bearer " + user.AccessToken);
60+
var config = new Configuration(new ApiClient(basePath));
61+
config.AddDefaultHeader("Authorization", "Bearer " + accessToken);
5462
EnvelopesApi envelopesApi = new EnvelopesApi(config);
55-
EnvelopeSummary results = envelopesApi.CreateEnvelope(RequestItemsService.Session.AccountId, env);
63+
EnvelopeSummary results = envelopesApi.CreateEnvelope(accountId, env);
5664
RequestItemsService.EnvelopeId = results.EnvelopeId;
5765
return results;
5866
}
5967

6068
private EnvelopeDefinition MakeEnvelope(string signerEmail, string signerName, string ccEmail, string ccName)
6169
{
70+
// Data for this method
71+
// signerEmail
72+
// signerName
73+
// ccEmail
74+
// ccName
75+
// Config.docDocx
76+
// Config.docPdf
77+
// RequestItemsService.Status -- the envelope status ('created' or 'sent')
78+
79+
6280
// document 1 (html) has tag **signature_1**
6381
// document 2 (docx) has tag /sn1/
6482
// document 3 (pdf) has tag /sn1/
@@ -75,6 +93,8 @@ private EnvelopeDefinition MakeEnvelope(string signerEmail, string signerName, s
7593
// create the envelope definition
7694
EnvelopeDefinition env = new EnvelopeDefinition();
7795
env.EmailSubject = "Please sign this document set";
96+
97+
// Create document objects, one per document
7898
Document doc1 = new Document();
7999
string b64 = Convert.ToBase64String(document1(signerEmail, signerName, ccEmail, ccName));
80100
doc1.DocumentBase64 = b64;
@@ -87,16 +107,13 @@ private EnvelopeDefinition MakeEnvelope(string signerEmail, string signerName, s
87107
FileExtension = "docx",
88108
DocumentId = "2"
89109
};
90-
91110
Document doc3 = new Document
92111
{
93112
DocumentBase64 = doc3PdfBytes,
94113
Name = "Lorem Ipsum", // can be different from actual file name
95114
FileExtension = "pdf",
96115
DocumentId = "3"
97116
};
98-
99-
100117
// The order in the docs array determines the order in the envelope
101118
env.Documents = new List<Document> { doc1, doc2, doc3};
102119

@@ -146,12 +163,10 @@ private EnvelopeDefinition MakeEnvelope(string signerEmail, string signerName, s
146163
AnchorXOffset = "20"
147164
};
148165

149-
150166
// Tabs are set per recipient / signer
151167
Tabs signer1Tabs = new Tabs {
152168
SignHereTabs = new List<SignHere> { signHere1, signHere2}
153169
};
154-
155170
signer1.Tabs = signer1Tabs;
156171

157172
// Add the recipients to the envelope object
@@ -160,9 +175,7 @@ private EnvelopeDefinition MakeEnvelope(string signerEmail, string signerName, s
160175
Signers = new List<Signer> { signer1 },
161176
CarbonCopies = new List<CarbonCopy> { cc1 }
162177
};
163-
164178
env.Recipients = recipients;
165-
166179
// Request that the envelope be sent by setting |status| to "sent".
167180
// To request that the envelope be created as a draft, set to "created"
168181
env.Status = RequestItemsService.Status;
@@ -172,6 +185,12 @@ private EnvelopeDefinition MakeEnvelope(string signerEmail, string signerName, s
172185

173186
private byte[] document1(string signerEmail, string signerName, string ccEmail, string ccName)
174187
{
188+
// Data for this method
189+
// signerEmail
190+
// signerName
191+
// ccEmail
192+
// ccName
193+
175194
return Encoding.UTF8.GetBytes(
176195
" <!DOCTYPE html>\n" +
177196
" <html>\n" +

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ public Eg003ListEnvelopesController(DSConfiguration config, IRequestItemsService
2626
[HttpPost]
2727
public IActionResult Create(string signerEmail, string signerName)
2828
{
29+
// Data for this method
30+
var accessToken = RequestItemsService.User.AccessToken;
31+
var basePath = RequestItemsService.Session.BasePath + "/restapi";
32+
var accountId = RequestItemsService.Session.AccountId;
33+
34+
// Check the token with minimal buffer time.
2935
bool tokenOk = CheckToken(3);
3036
if (!tokenOk)
3137
{
@@ -37,16 +43,13 @@ public IActionResult Create(string signerEmail, string signerName)
3743
RequestItemsService.EgName = EgName;
3844
return Redirect("/ds/mustAuthenticate");
3945
}
40-
var session = RequestItemsService.Session;
41-
var user = RequestItemsService.User;
42-
var config = new Configuration(new ApiClient(session.BasePath + "/restapi"));
43-
config.AddDefaultHeader("Authorization", "Bearer " + user.AccessToken);
46+
var config = new Configuration(new ApiClient(basePath));
47+
config.AddDefaultHeader("Authorization", "Bearer " + accessToken);
4448
EnvelopesApi envelopesApi = new EnvelopesApi(config);
45-
ListStatusChangesOptions options = new ListStatusChangesOptions();
46-
49+
ListStatusChangesOptions options = new ListStatusChangesOptions();
4750
options.fromDate = DateTime.Now.AddDays(-30).ToString("yyyy/MM/dd");
48-
49-
EnvelopesInformation results = envelopesApi.ListStatusChanges(RequestItemsService.Session.AccountId, options);
51+
// Call the API method:
52+
EnvelopesInformation results = envelopesApi.ListStatusChanges(accountId, options);
5053

5154
ViewBag.h1 = "List envelopes results";
5255
ViewBag.message = "Results from the Envelopes::listStatusChanges method:";

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ public Eg004EnvelopeInfoController(DSConfiguration config, IRequestItemsService
2424
[HttpPost]
2525
public IActionResult Create(string signerEmail, string signerName)
2626
{
27+
// Data for this method
28+
var accessToken = RequestItemsService.User.AccessToken;
29+
var basePath = RequestItemsService.Session.BasePath + "/restapi";
30+
var accountId = RequestItemsService.Session.AccountId;
31+
var envelopeId = RequestItemsService.EnvelopeId;
32+
33+
// Check the token with minimal buffer time.
2734
bool tokenOk = CheckToken(3);
2835
if (!tokenOk)
2936
{
@@ -35,14 +42,12 @@ public IActionResult Create(string signerEmail, string signerName)
3542
RequestItemsService.EgName = EgName;
3643
return Redirect("/ds/mustAuthenticate");
3744
}
38-
var session = RequestItemsService.Session;
39-
var user = RequestItemsService.User;
40-
var config = new Configuration(new ApiClient(session.BasePath + "/restapi"));
41-
config.AddDefaultHeader("Authorization", "Bearer " + user.AccessToken);
45+
var config = new Configuration(new ApiClient(basePath));
46+
config.AddDefaultHeader("Authorization", "Bearer " + accessToken);
4247
EnvelopesApi envelopesApi = new EnvelopesApi(config);
4348
ViewBag.h1 = "Get envelope status results";
4449
ViewBag.message = "Results from the Envelopes::get method:";
45-
DocuSign.eSign.Model.Envelope results = envelopesApi.GetEnvelope(RequestItemsService.Session.AccountId, RequestItemsService.EnvelopeId);
50+
DocuSign.eSign.Model.Envelope results = envelopesApi.GetEnvelope(accountId, envelopeId);
4651
ViewBag.Locals.Json = JsonConvert.SerializeObject(results, Formatting.Indented);
4752

4853
return View("example_done");

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ public Eg005EnvelopeRecipientsController(DSConfiguration config, IRequestItemsSe
2020
[HttpPost]
2121
public IActionResult Create(string signerEmail, string signerName)
2222
{
23+
// Data for this method
24+
var accessToken = RequestItemsService.User.AccessToken;
25+
var basePath = RequestItemsService.Session.BasePath + "/restapi";
26+
var accountId = RequestItemsService.Session.AccountId;
27+
var envelopeId = RequestItemsService.EnvelopeId;
28+
2329
bool tokenOk = CheckToken(3);
2430
if (!tokenOk)
2531
{
@@ -31,14 +37,12 @@ public IActionResult Create(string signerEmail, string signerName)
3137
RequestItemsService.EgName = EgName;
3238
return Redirect("/ds/mustAuthenticate");
3339
}
34-
var session = RequestItemsService.Session;
35-
var user = RequestItemsService.User;
36-
var config = new Configuration(new ApiClient(session.BasePath + "/restapi"));
37-
config.AddDefaultHeader("Authorization", "Bearer " + user.AccessToken);
40+
var config = new Configuration(new ApiClient(basePath));
41+
config.AddDefaultHeader("Authorization", "Bearer " + accessToken);
3842
EnvelopesApi envelopesApi = new EnvelopesApi(config);
3943
ViewBag.h1 = "List envelope recipients result";
4044
ViewBag.message = "Results from the EnvelopeRecipients::list method:";
41-
var results = envelopesApi.ListRecipients(RequestItemsService.Session.AccountId, RequestItemsService.EnvelopeId);
45+
var results = envelopesApi.ListRecipients(accountId, envelopeId);
4246
ViewBag.Locals.Json = JsonConvert.SerializeObject(results, Formatting.Indented);
4347

4448
return View("example_done");

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ public Eg006EnvelopeDocsController(DSConfiguration config, IRequestItemsService
2222
[HttpPost]
2323
public IActionResult Create(string signerEmail, string signerName)
2424
{
25+
// Data for this method
26+
var accessToken = RequestItemsService.User.AccessToken;
27+
var basePath = RequestItemsService.Session.BasePath + "/restapi";
28+
var accountId = RequestItemsService.Session.AccountId;
29+
var envelopeId = RequestItemsService.EnvelopeId;
30+
31+
2532
bool tokenOk = CheckToken(3);
2633
if (!tokenOk)
2734
{
@@ -33,16 +40,12 @@ public IActionResult Create(string signerEmail, string signerName)
3340
RequestItemsService.EgName = EgName;
3441
return Redirect("/ds/mustAuthenticate");
3542
}
36-
var session = RequestItemsService.Session;
37-
var user = RequestItemsService.User;
38-
var config = new Configuration(new ApiClient(session.BasePath + "/restapi"));
39-
config.AddDefaultHeader("Authorization", "Bearer " + user.AccessToken);
43+
var config = new Configuration(new ApiClient(basePath));
44+
config.AddDefaultHeader("Authorization", "Bearer " + accessToken);
4045
EnvelopesApi envelopesApi = new EnvelopesApi(config);
41-
EnvelopeDocumentsResult result = envelopesApi.ListDocuments(RequestItemsService.Session.AccountId,
42-
RequestItemsService.EnvelopeId);
46+
EnvelopeDocumentsResult result = envelopesApi.ListDocuments(accountId, envelopeId);
4347
// Save the envelopeId and its list of documents in the session so
4448
// they can be used in example 7 (download a document)
45-
4649
List<EnvelopeDocItem> envelopeDocItems = new List<EnvelopeDocItem>();
4750
envelopeDocItems.Add(new EnvelopeDocItem { Name= "Combined", Type= "content", DocumentId = "combined" });
4851
envelopeDocItems.Add(new EnvelopeDocItem { Name = "Zip archive", Type = "zip", DocumentId = "archive" });
@@ -57,7 +60,7 @@ public IActionResult Create(string signerEmail, string signerName)
5760
}
5861

5962
EnvelopeDocuments envelopeDocuments = new EnvelopeDocuments();
60-
envelopeDocuments.EnvelopeId = RequestItemsService.EnvelopeId;
63+
envelopeDocuments.EnvelopeId = envelopeId;
6164
envelopeDocuments.Documents = envelopeDocItems;
6265
RequestItemsService.EnvelopeDocuments = envelopeDocuments;
6366

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@ public Eg007EnvelopeGetDocController(DSConfiguration config, IRequestItemsServic
2020
[HttpPost]
2121
public ActionResult Create(string docSelect)
2222
{
23+
// Data for this method
24+
// docSelect -- argument
25+
var accessToken = RequestItemsService.User.AccessToken;
26+
var basePath = RequestItemsService.Session.BasePath + "/restapi";
27+
var accountId = RequestItemsService.Session.AccountId;
28+
var envelopeId = RequestItemsService.EnvelopeId;
29+
// documents data for the envelope. See example EG006
30+
var documents = RequestItemsService.EnvelopeDocuments.Documents;
31+
2332
bool tokenOk = CheckToken(3);
2433
if (!tokenOk)
2534
{
@@ -31,17 +40,14 @@ public ActionResult Create(string docSelect)
3140
RequestItemsService.EgName = EgName;
3241
return Redirect("/ds/mustAuthenticate");
3342
}
34-
var session = RequestItemsService.Session;
35-
var user = RequestItemsService.User;
36-
var config = new Configuration(new ApiClient(session.BasePath + "/restapi"));
37-
config.AddDefaultHeader("Authorization", "Bearer " + user.AccessToken);
43+
var config = new Configuration(new ApiClient(basePath));
44+
config.AddDefaultHeader("Authorization", "Bearer " + accessToken);
3845
EnvelopesApi envelopesApi = new EnvelopesApi(config);
3946

4047
// Step 1. EnvelopeDocuments::get.
4148
// Exceptions will be caught by the calling function
42-
System.IO.Stream results = envelopesApi.GetDocument(RequestItemsService.Session.AccountId,
43-
RequestItemsService.EnvelopeId, docSelect);
44-
var documents = RequestItemsService.EnvelopeDocuments.Documents;
49+
System.IO.Stream results = envelopesApi.GetDocument(accountId,
50+
envelopeId, docSelect);
4551
EnvelopeDocItem docItem = documents.FirstOrDefault(d => docSelect.Equals(d.DocumentId));
4652

4753
string docName = docItem.Name;

0 commit comments

Comments
 (0)