forked from docusign/code-examples-csharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEg05GetClickwrapResponsesController.cs
More file actions
76 lines (65 loc) · 2.76 KB
/
Eg05GetClickwrapResponsesController.cs
File metadata and controls
76 lines (65 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using DocuSign.Click.Api;
using DocuSign.Click.Client;
using DocuSign.CodeExamples.Common;
using DocuSign.CodeExamples.Controllers;
using DocuSign.CodeExamples.Models;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
namespace DocuSign.CodeExamples.Click.Controllers
{
[Area("Click")]
[Route("[area]/Eg07")]
public class Eg07GetClickwrapResponsesController : EgController
{
public Eg07GetClickwrapResponsesController(
DSConfiguration dsConfig,
IRequestItemsService requestItemsService)
: base(dsConfig, requestItemsService)
{
}
public override string EgName => "Eg07";
protected override void InitializeInternal()
{
ViewBag.ClickwrapId = RequestItemsService.ClickwrapId;
ViewBag.AccountId = RequestItemsService.Session.AccountId;
}
[MustAuthenticate]
[Route("Create")]
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create()
{
// Step 1. Obtain your OAuth token
var accessToken = RequestItemsService.User.AccessToken;
var basePath = $"{RequestItemsService.Session.BasePath}/clickapi"; // Base API path
// Step 2: Construct your API headers
var apiClient = new ApiClient(basePath);
apiClient.Configuration.DefaultHeader.Add("Authorization", "Bearer " + accessToken);
var clickAccountApi = new AccountsApi(apiClient);
try
{
if (string.IsNullOrEmpty(RequestItemsService.ClickwrapId))
{
ViewBag.errorCode = 400;
ViewBag.errorMessage = "Cannot find any clickwrap. Please first create a clickwrap using the first example.";
return View("Error");
}
var accountId = RequestItemsService.Session.AccountId;
var clickwrapId = RequestItemsService.ClickwrapId;
// Step 3: Call the Click API to get a clickwrap agreements
var clickWrapAgreements = clickAccountApi.GetClickwrapAgreements(accountId, clickwrapId);
//Show results
ViewBag.h1 = "The data was successfully fetched";
ViewBag.message = $"The clickwrap contains {clickWrapAgreements.UserAgreements.Count} agreements.";
ViewBag.Locals.Json = JsonConvert.SerializeObject(clickWrapAgreements, Formatting.Indented);
return View("example_done");
}
catch (ApiException apiException)
{
ViewBag.errorCode = apiException.ErrorCode;
ViewBag.errorMessage = apiException.Message;
return View("Error");
}
}
}
}