Skip to content

Commit 052ac8b

Browse files
author
Raileen Del Rosario
committed
2 parents a3ceeda + a9a73d8 commit 052ac8b

File tree

7 files changed

+267
-0
lines changed

7 files changed

+267
-0
lines changed

launcher-csharp/Common/IRequestItemsService.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ public interface IRequestItemsService
4444

4545
public string WorkspaceId { get; set; }
4646

47+
public string CreatorId { get; set; }
48+
4749
public string WorkspaceDocumentId { get; set; }
4850

4951
public bool IsWorkflowPublished { get; set; }

launcher-csharp/Common/RequestItemsService.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,12 @@ public string WorkspaceId
168168
set => this.cache.Set(this.GetKey("WorkspaceId"), value);
169169
}
170170

171+
public string CreatorId
172+
{
173+
get => this.cache.Get<string>(this.GetKey("CreatorId"));
174+
set => this.cache.Set(this.GetKey("CreatorId"), value);
175+
}
176+
171177
public string WorkspaceDocumentId
172178
{
173179
get => this.cache.Get<string>(this.GetKey("WorkspaceDocumentId"));

launcher-csharp/Workspaces/Controllers/Work001CreateWorkspace.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public IActionResult Create(string workspaceName)
4545
workspaceName);
4646

4747
this.RequestItemsService.WorkspaceId = createWorkspaceResponse.Result.WorkspaceId;
48+
this.RequestItemsService.CreatorId = createWorkspaceResponse.Result.CreatedByUserId;
4849

4950
this.ViewBag.h1 = this.CodeExampleText.ExampleName;
5051
this.ViewBag.message = string.Format(
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// <copyright file="Work005CreateUploadRequest.cs" company="Docusign">
2+
// Copyright (c) Docusign. All rights reserved.
3+
// </copyright>
4+
5+
namespace DocuSign.CodeExamples.Controllers
6+
{
7+
using System;
8+
using DocuSign.CodeExamples.Common;
9+
using DocuSign.CodeExamples.Examples;
10+
using DocuSign.CodeExamples.Models;
11+
using Microsoft.AspNetCore.Mvc;
12+
13+
[Area("Workspaces")]
14+
[Route("work005")]
15+
public class Work005CreateUploadRequest : EgController
16+
{
17+
public Work005CreateUploadRequest(DsConfiguration dsConfig,
18+
LauncherTexts launcherTexts,
19+
IRequestItemsService requestItemsService)
20+
: base(dsConfig, launcherTexts, requestItemsService)
21+
{
22+
this.CodeExampleText = this.GetExampleText(this.EgName, ExamplesApiType.Workspaces);
23+
this.ViewBag.title = this.CodeExampleText.ExampleName;
24+
}
25+
26+
public override string EgName => "work005";
27+
28+
[MustAuthenticate]
29+
[HttpGet]
30+
public override IActionResult Get()
31+
{
32+
IActionResult actionResult = base.Get();
33+
if (this.RequestItemsService.EgName == this.EgName)
34+
{
35+
return actionResult;
36+
}
37+
38+
this.ViewBag.WorkspaceIdOk = this.RequestItemsService.WorkspaceId != null;
39+
this.ViewBag.CreatorIdOk = this.RequestItemsService.CreatorId != null;
40+
41+
return this.View("work005", this);
42+
}
43+
44+
[HttpPost]
45+
[SetViewBag]
46+
public IActionResult Create(string assigneeEmail)
47+
{
48+
bool tokenOk = this.CheckToken(3);
49+
if (!tokenOk)
50+
{
51+
this.RequestItemsService.EgName = this.EgName;
52+
return this.Redirect("/ds/mustAuthenticate");
53+
}
54+
55+
var accessToken = this.RequestItemsService.User.AccessToken;
56+
var accountId = this.RequestItemsService.Session.AccountId;
57+
var creatorId = this.RequestItemsService.CreatorId;
58+
var workspaceId = this.RequestItemsService.WorkspaceId;
59+
60+
try
61+
{
62+
var results = CreateUploadRequest.CreateUploadRequestWithDueDate(
63+
accessToken,
64+
accountId,
65+
workspaceId,
66+
creatorId,
67+
assigneeEmail);
68+
69+
this.ViewBag.message = string.Format(this.CodeExampleText.ResultsPageText, results.Result.UploadRequestId);
70+
}
71+
catch (Exception ex)
72+
{
73+
this.ViewBag.message = this.CodeExampleText.CustomErrorTexts[0].ErrorMessage;
74+
}
75+
76+
this.ViewBag.h1 = this.CodeExampleText.ExampleName;
77+
return this.View("example_done");
78+
}
79+
}
80+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// <copyright file="CreateUploadRequest.cs" company="Docusign">
2+
// Copyright (c) Docusign. All rights reserved.
3+
// </copyright>
4+
5+
namespace DocuSign.CodeExamples.Examples
6+
{
7+
using System;
8+
using System.Collections.Generic;
9+
using System.Threading.Tasks;
10+
using Docusign.IAM.SDK;
11+
using Docusign.IAM.SDK.Models.Components;
12+
13+
public static class CreateUploadRequest
14+
{
15+
public static async Task<GetWorkspaceUploadRequestResponse> CreateUploadRequestWithDueDate(
16+
string accessToken,
17+
string accountId,
18+
string workspaceId,
19+
string creatorId,
20+
string assigneeEmail)
21+
{
22+
//ds-snippet-start:Workspaces5Step2
23+
var client = CreateAuthenticatedClient(accessToken);
24+
var dueDate = DateTime.Now.AddDays(7);
25+
//ds-snippet-end:Workspaces5Step2
26+
27+
//ds-snippet-start:Workspaces5Step3
28+
var createUploadRequest = new CreateWorkspaceUploadRequestBody()
29+
{
30+
Name = $"Upload Request example {dueDate}",
31+
Description = "This is an example upload request created via the workspaces API",
32+
DueDate = dueDate,
33+
Assignments = new List<CreateWorkspaceUploadRequestAssignment>
34+
{
35+
new CreateWorkspaceUploadRequestAssignment
36+
{
37+
Email = assigneeEmail,
38+
UploadRequestResponsibilityTypeId = WorkspaceUploadRequestResponsibilityType.Assignee,
39+
FirstName = "Test",
40+
LastName = "User",
41+
},
42+
new CreateWorkspaceUploadRequestAssignment
43+
{
44+
AssigneeUserId = creatorId,
45+
UploadRequestResponsibilityTypeId = WorkspaceUploadRequestResponsibilityType.Watcher,
46+
},
47+
},
48+
Status = WorkspaceUploadRequestStatus.Draft,
49+
};
50+
//ds-snippet-end:Workspaces5Step3
51+
52+
//ds-snippet-start:Workspaces5Step4
53+
return await client.Workspaces.WorkspaceUploadRequest.CreateWorkspaceUploadRequestAsync(
54+
accountId,
55+
workspaceId,
56+
createUploadRequest);
57+
}
58+
59+
//ds-snippet-end:Workspaces5Step4
60+
61+
private static IamClient CreateAuthenticatedClient(string accessToken)
62+
{
63+
return IamClient.Builder()
64+
.WithAccessToken(accessToken)
65+
.Build();
66+
}
67+
}
68+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
@{
2+
int formNumber = 0;
3+
int assigneeEmailInputNumber = 0;
4+
5+
string noWorkspaceRedirect = string.Format(
6+
ViewBag.CodeExampleText.RedirectsToOtherCodeExamples[0].RedirectText,
7+
string.Format("href=\"work00{0}\"", ViewBag.CodeExampleText.RedirectsToOtherCodeExamples[0].CodeExampleToRedirectTo)
8+
);
9+
10+
string noCreatorIdRedirect = string.Format(
11+
ViewBag.CodeExampleText.RedirectsToOtherCodeExamples[1].RedirectText,
12+
string.Format("href=\"work00{0}\"", ViewBag.CodeExampleText.RedirectsToOtherCodeExamples[1].CodeExampleToRedirectTo)
13+
);
14+
}
15+
16+
<h4>@Html.Raw(ViewBag.CodeExampleText.ExampleName)</h4>
17+
<p>
18+
@Html.Raw(ViewBag.CodeExampleText.ExampleDescription)
19+
</p>
20+
21+
@if (ViewBag.showDoc == true)
22+
{
23+
<p><a target='_blank' href='<%= documentation %>'>Documentation</a> about this example</p>
24+
}
25+
26+
<partial name="../../../Views/Shared/LinkToMethodView" model="ViewBag.CodeExampleText" />
27+
28+
<p>
29+
@Html.Raw(@String.Format(ViewBag.SupportingTexts.ViewSourceFile, "<a target='_blank' href=" + @ViewBag.source + ">CreateUploadRequest.cs</a>"))
30+
</p>
31+
32+
@if (ViewBag.WorkspaceIdOk == false)
33+
{
34+
@Html.Raw(
35+
noWorkspaceRedirect
36+
)
37+
38+
<form class="eg" action="work001" method="get">
39+
<button type="submit" class="btn btn-primary">@Html.Raw(ViewBag.SupportingTexts.ContinueButton)</button>
40+
</form>
41+
}
42+
else if (ViewBag.CreatorIdOk == false)
43+
{
44+
@Html.Raw(
45+
noCreatorIdRedirect
46+
)
47+
48+
<form class="eg" action="work001" method="get">
49+
<button type="submit" class="btn btn-primary">@Html.Raw(ViewBag.SupportingTexts.ContinueButton)</button>
50+
</form>
51+
}
52+
else
53+
{
54+
<form class="eg" action="" method="post" data-busy="form">
55+
<div class="form-group">
56+
<label for="assigneeEmail">
57+
@Html.Raw(ViewBag.CodeExampleText.Forms[formNumber].Inputs[assigneeEmailInputNumber].InputName)
58+
</label>
59+
<input type="email"
60+
class="form-control"
61+
id="assigneeEmail"
62+
name="assigneeEmail"
63+
aria-describedby="emailHelp"
64+
placeholder="@ViewBag.CodeExampleText.Forms[formNumber].Inputs[assigneeEmailInputNumber].InputPlaceholder"
65+
required
66+
value="@ViewBag.Locals.DsConfig.SignerEmail"/>
67+
<small id="emailHelp" class="form-text text-muted">@Html.Raw(ViewBag.SupportingTexts.HelpingTexts.EmailWontBeShared)</small>
68+
</div>
69+
70+
<input type="hidden" name="_csrf" value="<%- csrfToken %>">
71+
<button type="submit" class="btn btn-primary">@Html.Raw(ViewBag.SupportingTexts.SubmitButton)</button>
72+
</form>
73+
}

manifest/CodeExamplesManifest.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3132,6 +3132,43 @@
31323132
}
31333133
],
31343134
"ResultsPageText": "The workspace envelope has been created and sent!<br />Envelope ID {0}."
3135+
},
3136+
{
3137+
"ExampleNumber": 5,
3138+
"ExampleName": "Create a workspace upload request",
3139+
"ExampleDescription": "Creates a workspace upload request",
3140+
"LinksToAPIMethod": [
3141+
{
3142+
"Path": "https://developers.docusign.com/docs/workspaces-api/reference/workspaces/workspaceuploadrequest/createworkspaceuploadrequest/",
3143+
"PathName": "Workspaces:createWorkspaceUploadRequest"
3144+
}
3145+
],
3146+
"RedirectsToOtherCodeExamples": [
3147+
{
3148+
"CodeExampleToRedirectTo": 1,
3149+
"RedirectText": "<p>Prerequisite: Please create a workspace before running this example using <a {0}>Create a workspace</a>.</p>"
3150+
},
3151+
{
3152+
"CodeExampleToRedirectTo": 1,
3153+
"RedirectText": "<p>Prerequisite: No creator ID was recorded. Please run the <a {0}>Create Workspace</a> before running this code example.</p>"
3154+
}
3155+
],
3156+
"CustomErrorTexts": [
3157+
{
3158+
"ErrorMessageCheck": "UPLOAD_REQUEST_NOT_CREATED",
3159+
"ErrorMessage": "Failed to create Workspace upload request."
3160+
}
3161+
],
3162+
"Forms": [
3163+
{
3164+
"Inputs": [
3165+
{
3166+
"InputName": "Assignee email"
3167+
}
3168+
]
3169+
}
3170+
],
3171+
"ResultsPageText": "Workspace upload request created! ID: {0}."
31353172
}
31363173
]
31373174
}

0 commit comments

Comments
 (0)