Skip to content

Commit

Permalink
Added DoWork methods
Browse files Browse the repository at this point in the history
  • Loading branch information
LarryKlugerDS committed Dec 17, 2018
1 parent fea60e5 commit 4c6f4a0
Show file tree
Hide file tree
Showing 15 changed files with 610 additions and 367 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,20 @@ public Eg001EmbeddedSigningController(DSConfiguration config, IRequestItemsServi
ViewBag.title = "Embedded Signing Ceremony";
}

[HttpPost]
public IActionResult Create(string signerEmail, string signerName)
private string DoWork(string signerEmail, string signerName,
string accessToken, string basePath, string accountId)
{
// Data for this method
// signerEmail
// signerName
// accessToken
// basePath
// accountId

// 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)
{
// We could store the parameters of the requested operation
// so it could be restarted automatically.
// But since it should be rare to have a token issue here,
// we'll make the user re-enter the form data after
// authentication.
RequestItemsService.EgName = EgName;
return Redirect("/ds/mustAuthenticate");
}
// Step 1. Create the envelope definition
EnvelopeDefinition envelope = MakeEnvelope(signerEmail, signerName);

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

private RecipientViewRequest MakeRecipientViewRequest(string signerEmail, string signerName)
Expand Down Expand Up @@ -188,5 +177,36 @@ private EnvelopeDefinition MakeEnvelope(string signerEmail, string signerName)
}

public override string EgName => "eg001";

[HttpPost]
public IActionResult Create(string signerEmail, string signerName)
{
// Data for this method
// signerEmail
// signerName
// dsPingUrl -- class global
// signerClientId -- class global
// dsReturnUrl -- class global
string accessToken = RequestItemsService.User.AccessToken;
string basePath = RequestItemsService.Session.BasePath + "/restapi";
string accountId = RequestItemsService.Session.AccountId;

// Check the token with minimal buffer time.
bool tokenOk = CheckToken(3);
if (!tokenOk)
{
// We could store the parameters of the requested operation
// so it could be restarted automatically.
// But since it should be rare to have a token issue here,
// we'll make the user re-enter the form data after
// authentication.
RequestItemsService.EgName = EgName;
return Redirect("/ds/mustAuthenticate");
}

string redirectUrl = DoWork(signerEmail, signerName, accessToken, basePath, accountId);
// Redirect the user to the Signing Ceremony
return Redirect(redirectUrl);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using DocuSign.eSign.Api;
using DocuSign.eSign.Model;
using eg_03_csharp_auth_code_grant_core.Models;
using Microsoft.AspNetCore.Mvc;
using System.IO;
using System.Text;
using DocuSign.eSign.Client;

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

public override string EgName => "eg002";

[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)
{
// We could store the parameters of the requested operation
// so it could be restarted automatically.
// But since it should be rare to have a token issue here,
// we'll make the user re-enter the form data after
// authentication.
RequestItemsService.EgName = EgName;
return Redirect("/ds/mustAuthenticate");
}
EnvelopeSummary results = DoWork(signerEmail, signerName, ccEmail, ccName);
ViewBag.h1 = "Envelope sent";
ViewBag.message = "The envelope has been created and sent!<br />Envelope ID " + results.EnvelopeId + ".";
//return results;
return View("example_done");
}

public EnvelopeSummary DoWork(string signerEmail, string signerName, string ccEmail, string ccName)
{
// Data for this method
Expand Down Expand Up @@ -215,5 +190,26 @@ private byte[] document1(string signerEmail, string signerName, string ccEmail,
" </html>"
);
}

[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)
{
// We could store the parameters of the requested operation
// so it could be restarted automatically.
// But since it should be rare to have a token issue here,
// we'll make the user re-enter the form data after
// authentication.
RequestItemsService.EgName = EgName;
return Redirect("/ds/mustAuthenticate");
}
EnvelopeSummary results = DoWork(signerEmail, signerName, ccEmail, ccName);
ViewBag.h1 = "Envelope sent";
ViewBag.message = "The envelope has been created and sent!<br />Envelope ID " + results.EnvelopeId + ".";
return View("example_done");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,30 @@ public Eg003ListEnvelopesController(DSConfiguration config, IRequestItemsService

public override string EgName => "eg003";

private EnvelopesInformation DoWork(string accessToken, string basePath, string accountId)
{
// Data for this method
// accessToken
// basePath
// accountId

var config = new Configuration(new ApiClient(basePath));
config.AddDefaultHeader("Authorization", "Bearer " + accessToken);
EnvelopesApi envelopesApi = new EnvelopesApi(config);
ListStatusChangesOptions options = new ListStatusChangesOptions();
options.fromDate = DateTime.Now.AddDays(-30).ToString("yyyy/MM/dd");
// Call the API method:
EnvelopesInformation results = envelopesApi.ListStatusChanges(accountId, options);
return results;
}

[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;
string accessToken = RequestItemsService.User.AccessToken;
string basePath = RequestItemsService.Session.BasePath + "/restapi";
string accountId = RequestItemsService.Session.AccountId;

// Check the token with minimal buffer time.
bool tokenOk = CheckToken(3);
Expand All @@ -43,14 +60,10 @@ public IActionResult Create(string signerEmail, string signerName)
RequestItemsService.EgName = EgName;
return Redirect("/ds/mustAuthenticate");
}
var config = new Configuration(new ApiClient(basePath));
config.AddDefaultHeader("Authorization", "Bearer " + accessToken);
EnvelopesApi envelopesApi = new EnvelopesApi(config);
ListStatusChangesOptions options = new ListStatusChangesOptions();
options.fromDate = DateTime.Now.AddDays(-30).ToString("yyyy/MM/dd");
// Call the API method:
EnvelopesInformation results = envelopesApi.ListStatusChanges(accountId, options);


// Call the worker
EnvelopesInformation results = DoWork(accessToken, basePath, accountId);
// Process results
ViewBag.h1 = "List envelopes results";
ViewBag.message = "Results from the Envelopes::listStatusChanges method:";
ViewBag.Locals.Json = JsonConvert.SerializeObject(results,Formatting.Indented);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using DocuSign.eSign.Api;
using DocuSign.eSign.Api;
using DocuSign.eSign.Client;
using DocuSign.eSign.Model;
using eg_03_csharp_auth_code_grant_core.Models;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
Expand All @@ -21,6 +18,25 @@ public Eg004EnvelopeInfoController(DSConfiguration config, IRequestItemsService

public override string EgName => "eg004";

private Envelope DoWork(string accessToken, string basePath, string accountId,
string envelopeId)
{
// Data for this method
// accessToken
// basePath
// accountId
// envelopeId

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:";
Envelope results = envelopesApi.GetEnvelope(accountId, envelopeId);
return results;
}


[HttpPost]
public IActionResult Create(string signerEmail, string signerName)
{
Expand All @@ -42,14 +58,12 @@ public IActionResult Create(string signerEmail, string signerName)
RequestItemsService.EgName = EgName;
return Redirect("/ds/mustAuthenticate");
}
var config = new Configuration(new ApiClient(basePath));
config.AddDefaultHeader("Authorization", "Bearer " + accessToken);
EnvelopesApi envelopesApi = new EnvelopesApi(config);

Envelope results = DoWork(accessToken, basePath, accountId, envelopeId);

ViewBag.h1 = "Get envelope status results";
ViewBag.message = "Results from the Envelopes::get method:";
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
@@ -1,5 +1,6 @@
using DocuSign.eSign.Api;
using DocuSign.eSign.Client;
using DocuSign.eSign.Model;
using eg_03_csharp_auth_code_grant_core.Models;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
Expand All @@ -17,6 +18,24 @@ public Eg005EnvelopeRecipientsController(DSConfiguration config, IRequestItemsSe

public override string EgName => "eg005";

private Recipients DoWork(string accessToken, string basePath, string accountId,
string envelopeId)
{
// Data for this method
// accessToken
// basePath
// accountId
// envelopeId
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:";
Recipients results = envelopesApi.ListRecipients(accountId, envelopeId);
return results;
}


[HttpPost]
public IActionResult Create(string signerEmail, string signerName)
{
Expand All @@ -37,14 +56,8 @@ public IActionResult Create(string signerEmail, string signerName)
RequestItemsService.EgName = EgName;
return Redirect("/ds/mustAuthenticate");
}
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(accountId, envelopeId);
Recipients results = DoWork(accessToken, basePath, accountId, envelopeId);
ViewBag.Locals.Json = JsonConvert.SerializeObject(results, Formatting.Indented);

return View("example_done");
}
}
Expand Down
Loading

0 comments on commit 4c6f4a0

Please sign in to comment.