Skip to content

Commit

Permalink
Added method data comments
Browse files Browse the repository at this point in the history
  • Loading branch information
LarryKlugerDS committed Dec 17, 2018
1 parent be55160 commit fea60e5
Show file tree
Hide file tree
Showing 15 changed files with 471 additions and 315 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
using DocuSign.eSign.Api;
using DocuSign.eSign.Client;
using DocuSign.eSign.Model;
using eg_03_csharp_auth_code_grant_core.Common;
using eg_03_csharp_auth_code_grant_core.Controllers;
using eg_03_csharp_auth_code_grant_core.Models;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace eg_03_csharp_auth_code_grant_core.Views
Expand All @@ -29,6 +27,18 @@ public Eg001EmbeddedSigningController(DSConfiguration config, IRequestItemsServi
[HttpPost]
public IActionResult Create(string signerEmail, string signerName)
{
// Data for this method
// signerEmail
// signerName
// dsPingUrl -- class global
// signerClientId -- class global
// dsReturnUrl -- class global
var accessToken = RequestItemsService.User.AccessToken;
var basePath = RequestItemsService.Session.BasePath + "/restapi";
var accountId = RequestItemsService.Session.AccountId;


// Check the token with minimal buffer time.
bool tokenOk = CheckToken(3);
if (!tokenOk)
{
Expand All @@ -40,18 +50,14 @@ public IActionResult Create(string signerEmail, string signerName)
RequestItemsService.EgName = EgName;
return Redirect("/ds/mustAuthenticate");
}
var session = RequestItemsService.Session;
var user = RequestItemsService.User;
// Step 1. Create the envelope definition
EnvelopeDefinition envelope = MakeEnvelope(signerEmail, signerName);

// Step 2. Call DocuSign to create the envelope
var config = new Configuration(new ApiClient(session.BasePath+ "/restapi"));
config.AddDefaultHeader("Authorization", "Bearer "+ user.AccessToken);
var config = new Configuration(new ApiClient(basePath));
config.AddDefaultHeader("Authorization", "Bearer " + accessToken);
EnvelopesApi envelopesApi = new EnvelopesApi(config);

EnvelopeSummary results = envelopesApi.CreateEnvelope(session.AccountId, envelope);

EnvelopeSummary results = envelopesApi.CreateEnvelope(accountId, envelope);
string envelopeId = results.EnvelopeId;

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

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

private RecipientViewRequest MakeRecipientViewRequest(string signerEmail, string signerName)
{
// Data for this method
// signerEmail
// signerName
// dsPingUrl -- class global
// signerClientId -- class global
// dsReturnUrl -- class global


RecipientViewRequest viewRequest = new RecipientViewRequest();
// Set the url where you want the recipient to go once they are done signing
// should typically be a callback route somewhere in your app.
Expand Down Expand Up @@ -107,8 +121,15 @@ private RecipientViewRequest MakeRecipientViewRequest(string signerEmail, string

private EnvelopeDefinition MakeEnvelope(string signerEmail, string signerName)
{
byte[] buffer = System.IO.File.ReadAllBytes(Config.docPdf);
// Data for this method
// signerEmail
// signerName
// signerClientId -- class global
// Config.docPdf


byte[] buffer = System.IO.File.ReadAllBytes(Config.docPdf);

EnvelopeDefinition envelopeDefinition = new EnvelopeDefinition();
envelopeDefinition.EmailSubject = "Please sign this document";
Document doc1 = new Document();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public Eg002SigningViaEmailController(DSConfiguration config, IRequestItemsServi
[HttpPost]
public IActionResult Create(string signerEmail, string signerName, string ccEmail, string ccName)
{
// Check the token with minimal buffer time.
bool tokenOk = CheckToken(3);
if (!tokenOk)
{
Expand All @@ -46,19 +47,36 @@ public IActionResult Create(string signerEmail, string signerName, string ccEmai

public EnvelopeSummary DoWork(string signerEmail, string signerName, string ccEmail, string ccName)
{
var session = RequestItemsService.Session;
var user = RequestItemsService.User;
// Data for this method
// signerEmail
// signerName
// ccEmail
// ccName
var accessToken = RequestItemsService.User.AccessToken;
var basePath = RequestItemsService.Session.BasePath + "/restapi";
var accountId = RequestItemsService.Session.AccountId;

EnvelopeDefinition env = MakeEnvelope(signerEmail, signerName, ccEmail, ccName);
var config = new Configuration(new ApiClient(session.BasePath + "/restapi"));
config.AddDefaultHeader("Authorization", "Bearer " + user.AccessToken);
var config = new Configuration(new ApiClient(basePath));
config.AddDefaultHeader("Authorization", "Bearer " + accessToken);
EnvelopesApi envelopesApi = new EnvelopesApi(config);
EnvelopeSummary results = envelopesApi.CreateEnvelope(RequestItemsService.Session.AccountId, env);
EnvelopeSummary results = envelopesApi.CreateEnvelope(accountId, env);
RequestItemsService.EnvelopeId = results.EnvelopeId;
return results;
}

private EnvelopeDefinition MakeEnvelope(string signerEmail, string signerName, string ccEmail, string ccName)
{
// Data for this method
// signerEmail
// signerName
// ccEmail
// ccName
// Config.docDocx
// Config.docPdf
// RequestItemsService.Status -- the envelope status ('created' or 'sent')


// document 1 (html) has tag **signature_1**
// document 2 (docx) has tag /sn1/
// document 3 (pdf) has tag /sn1/
Expand All @@ -75,6 +93,8 @@ private EnvelopeDefinition MakeEnvelope(string signerEmail, string signerName, s
// create the envelope definition
EnvelopeDefinition env = new EnvelopeDefinition();
env.EmailSubject = "Please sign this document set";

// Create document objects, one per document
Document doc1 = new Document();
string b64 = Convert.ToBase64String(document1(signerEmail, signerName, ccEmail, ccName));
doc1.DocumentBase64 = b64;
Expand All @@ -87,16 +107,13 @@ private EnvelopeDefinition MakeEnvelope(string signerEmail, string signerName, s
FileExtension = "docx",
DocumentId = "2"
};

Document doc3 = new Document
{
DocumentBase64 = doc3PdfBytes,
Name = "Lorem Ipsum", // can be different from actual file name
FileExtension = "pdf",
DocumentId = "3"
};


// The order in the docs array determines the order in the envelope
env.Documents = new List<Document> { doc1, doc2, doc3};

Expand Down Expand Up @@ -146,12 +163,10 @@ private EnvelopeDefinition MakeEnvelope(string signerEmail, string signerName, s
AnchorXOffset = "20"
};


// Tabs are set per recipient / signer
Tabs signer1Tabs = new Tabs {
SignHereTabs = new List<SignHere> { signHere1, signHere2}
};

signer1.Tabs = signer1Tabs;

// Add the recipients to the envelope object
Expand All @@ -160,9 +175,7 @@ private EnvelopeDefinition MakeEnvelope(string signerEmail, string signerName, s
Signers = new List<Signer> { signer1 },
CarbonCopies = new List<CarbonCopy> { cc1 }
};

env.Recipients = recipients;

// Request that the envelope be sent by setting |status| to "sent".
// To request that the envelope be created as a draft, set to "created"
env.Status = RequestItemsService.Status;
Expand All @@ -172,6 +185,12 @@ private EnvelopeDefinition MakeEnvelope(string signerEmail, string signerName, s

private byte[] document1(string signerEmail, string signerName, string ccEmail, string ccName)
{
// Data for this method
// signerEmail
// signerName
// ccEmail
// ccName

return Encoding.UTF8.GetBytes(
" <!DOCTYPE html>\n" +
" <html>\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ public Eg003ListEnvelopesController(DSConfiguration config, IRequestItemsService
[HttpPost]
public IActionResult Create(string signerEmail, string signerName)
{
// Data for this method
var accessToken = RequestItemsService.User.AccessToken;
var basePath = RequestItemsService.Session.BasePath + "/restapi";
var accountId = RequestItemsService.Session.AccountId;

// Check the token with minimal buffer time.
bool tokenOk = CheckToken(3);
if (!tokenOk)
{
Expand All @@ -37,16 +43,13 @@ public IActionResult Create(string signerEmail, string signerName)
RequestItemsService.EgName = EgName;
return Redirect("/ds/mustAuthenticate");
}
var session = RequestItemsService.Session;
var user = RequestItemsService.User;
var config = new Configuration(new ApiClient(session.BasePath + "/restapi"));
config.AddDefaultHeader("Authorization", "Bearer " + user.AccessToken);
var config = new Configuration(new ApiClient(basePath));
config.AddDefaultHeader("Authorization", "Bearer " + accessToken);
EnvelopesApi envelopesApi = new EnvelopesApi(config);
ListStatusChangesOptions options = new ListStatusChangesOptions();

ListStatusChangesOptions options = new ListStatusChangesOptions();
options.fromDate = DateTime.Now.AddDays(-30).ToString("yyyy/MM/dd");

EnvelopesInformation results = envelopesApi.ListStatusChanges(RequestItemsService.Session.AccountId, options);
// Call the API method:
EnvelopesInformation results = envelopesApi.ListStatusChanges(accountId, options);

ViewBag.h1 = "List envelopes results";
ViewBag.message = "Results from the Envelopes::listStatusChanges method:";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ public Eg004EnvelopeInfoController(DSConfiguration config, IRequestItemsService
[HttpPost]
public IActionResult Create(string signerEmail, string signerName)
{
// Data for this method
var accessToken = RequestItemsService.User.AccessToken;
var basePath = RequestItemsService.Session.BasePath + "/restapi";
var accountId = RequestItemsService.Session.AccountId;
var envelopeId = RequestItemsService.EnvelopeId;

// Check the token with minimal buffer time.
bool tokenOk = CheckToken(3);
if (!tokenOk)
{
Expand All @@ -35,14 +42,12 @@ public IActionResult Create(string signerEmail, string signerName)
RequestItemsService.EgName = EgName;
return Redirect("/ds/mustAuthenticate");
}
var session = RequestItemsService.Session;
var user = RequestItemsService.User;
var config = new Configuration(new ApiClient(session.BasePath + "/restapi"));
config.AddDefaultHeader("Authorization", "Bearer " + user.AccessToken);
var config = new Configuration(new ApiClient(basePath));
config.AddDefaultHeader("Authorization", "Bearer " + accessToken);
EnvelopesApi envelopesApi = new EnvelopesApi(config);
ViewBag.h1 = "Get envelope status results";
ViewBag.message = "Results from the Envelopes::get method:";
DocuSign.eSign.Model.Envelope results = envelopesApi.GetEnvelope(RequestItemsService.Session.AccountId, RequestItemsService.EnvelopeId);
DocuSign.eSign.Model.Envelope results = envelopesApi.GetEnvelope(accountId, envelopeId);
ViewBag.Locals.Json = JsonConvert.SerializeObject(results, Formatting.Indented);

return View("example_done");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ public Eg005EnvelopeRecipientsController(DSConfiguration config, IRequestItemsSe
[HttpPost]
public IActionResult Create(string signerEmail, string signerName)
{
// Data for this method
var accessToken = RequestItemsService.User.AccessToken;
var basePath = RequestItemsService.Session.BasePath + "/restapi";
var accountId = RequestItemsService.Session.AccountId;
var envelopeId = RequestItemsService.EnvelopeId;

bool tokenOk = CheckToken(3);
if (!tokenOk)
{
Expand All @@ -31,14 +37,12 @@ public IActionResult Create(string signerEmail, string signerName)
RequestItemsService.EgName = EgName;
return Redirect("/ds/mustAuthenticate");
}
var session = RequestItemsService.Session;
var user = RequestItemsService.User;
var config = new Configuration(new ApiClient(session.BasePath + "/restapi"));
config.AddDefaultHeader("Authorization", "Bearer " + user.AccessToken);
var config = new Configuration(new ApiClient(basePath));
config.AddDefaultHeader("Authorization", "Bearer " + accessToken);
EnvelopesApi envelopesApi = new EnvelopesApi(config);
ViewBag.h1 = "List envelope recipients result";
ViewBag.message = "Results from the EnvelopeRecipients::list method:";
var results = envelopesApi.ListRecipients(RequestItemsService.Session.AccountId, RequestItemsService.EnvelopeId);
var results = envelopesApi.ListRecipients(accountId, envelopeId);
ViewBag.Locals.Json = JsonConvert.SerializeObject(results, Formatting.Indented);

return View("example_done");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ public Eg006EnvelopeDocsController(DSConfiguration config, IRequestItemsService
[HttpPost]
public IActionResult Create(string signerEmail, string signerName)
{
// Data for this method
var accessToken = RequestItemsService.User.AccessToken;
var basePath = RequestItemsService.Session.BasePath + "/restapi";
var accountId = RequestItemsService.Session.AccountId;
var envelopeId = RequestItemsService.EnvelopeId;


bool tokenOk = CheckToken(3);
if (!tokenOk)
{
Expand All @@ -33,16 +40,12 @@ public IActionResult Create(string signerEmail, string signerName)
RequestItemsService.EgName = EgName;
return Redirect("/ds/mustAuthenticate");
}
var session = RequestItemsService.Session;
var user = RequestItemsService.User;
var config = new Configuration(new ApiClient(session.BasePath + "/restapi"));
config.AddDefaultHeader("Authorization", "Bearer " + user.AccessToken);
var config = new Configuration(new ApiClient(basePath));
config.AddDefaultHeader("Authorization", "Bearer " + accessToken);
EnvelopesApi envelopesApi = new EnvelopesApi(config);
EnvelopeDocumentsResult result = envelopesApi.ListDocuments(RequestItemsService.Session.AccountId,
RequestItemsService.EnvelopeId);
EnvelopeDocumentsResult result = envelopesApi.ListDocuments(accountId, envelopeId);
// Save the envelopeId and its list of documents in the session so
// they can be used in example 7 (download a document)

List<EnvelopeDocItem> envelopeDocItems = new List<EnvelopeDocItem>();
envelopeDocItems.Add(new EnvelopeDocItem { Name= "Combined", Type= "content", DocumentId = "combined" });
envelopeDocItems.Add(new EnvelopeDocItem { Name = "Zip archive", Type = "zip", DocumentId = "archive" });
Expand All @@ -57,7 +60,7 @@ public IActionResult Create(string signerEmail, string signerName)
}

EnvelopeDocuments envelopeDocuments = new EnvelopeDocuments();
envelopeDocuments.EnvelopeId = RequestItemsService.EnvelopeId;
envelopeDocuments.EnvelopeId = envelopeId;
envelopeDocuments.Documents = envelopeDocItems;
RequestItemsService.EnvelopeDocuments = envelopeDocuments;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ public Eg007EnvelopeGetDocController(DSConfiguration config, IRequestItemsServic
[HttpPost]
public ActionResult Create(string docSelect)
{
// Data for this method
// docSelect -- argument
var accessToken = RequestItemsService.User.AccessToken;
var basePath = RequestItemsService.Session.BasePath + "/restapi";
var accountId = RequestItemsService.Session.AccountId;
var envelopeId = RequestItemsService.EnvelopeId;
// documents data for the envelope. See example EG006
var documents = RequestItemsService.EnvelopeDocuments.Documents;

bool tokenOk = CheckToken(3);
if (!tokenOk)
{
Expand All @@ -31,17 +40,14 @@ public ActionResult Create(string docSelect)
RequestItemsService.EgName = EgName;
return Redirect("/ds/mustAuthenticate");
}
var session = RequestItemsService.Session;
var user = RequestItemsService.User;
var config = new Configuration(new ApiClient(session.BasePath + "/restapi"));
config.AddDefaultHeader("Authorization", "Bearer " + user.AccessToken);
var config = new Configuration(new ApiClient(basePath));
config.AddDefaultHeader("Authorization", "Bearer " + accessToken);
EnvelopesApi envelopesApi = new EnvelopesApi(config);

// Step 1. EnvelopeDocuments::get.
// Exceptions will be caught by the calling function
System.IO.Stream results = envelopesApi.GetDocument(RequestItemsService.Session.AccountId,
RequestItemsService.EnvelopeId, docSelect);
var documents = RequestItemsService.EnvelopeDocuments.Documents;
System.IO.Stream results = envelopesApi.GetDocument(accountId,
envelopeId, docSelect);
EnvelopeDocItem docItem = documents.FirstOrDefault(d => docSelect.Equals(d.DocumentId));

string docName = docItem.Name;
Expand Down
Loading

0 comments on commit fea60e5

Please sign in to comment.