Skip to content

Commit 270732d

Browse files
committed
added delete restore code example
1 parent 960b275 commit 270732d

File tree

10 files changed

+287
-5
lines changed

10 files changed

+287
-5
lines changed

JWT-Console/JWT-Console.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
</ItemGroup>
3030

3131
<ItemGroup>
32-
<PackageReference Include="DocuSign.eSign.dll" Version="8.2.0" />
32+
<PackageReference Include="DocuSign.eSign.dll" Version="8.4.0" />
3333
<PackageReference Include="System.Configuration.ConfigurationManager" Version="7.0.0" />
3434
<PackageReference Include="System.Runtime.Caching" Version="7.0.0" />
3535
</ItemGroup>

Quick_ACG/Quick_ACG.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848

4949
<ItemGroup>
5050
<PackageReference Include="DocuSign.Admin" Version="2.0.2" />
51-
<PackageReference Include="DocuSign.eSign.dll" Version="8.2.0" />
51+
<PackageReference Include="DocuSign.eSign.dll" Version="8.4.0" />
5252
<PackageReference Include="Microsoft.AspNetCore.Session" Version="2.3.0" />
5353
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.10" />
5454
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.10">

launcher-csharp.Tests/launcher-csharp.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
<ItemGroup>
2727
<PackageReference Include="DocuSign.Admin" Version="2.0.2" />
28-
<PackageReference Include="DocuSign.eSign.dll" Version="8.2.0" />
28+
<PackageReference Include="DocuSign.eSign.dll" Version="8.4.0" />
2929
<PackageReference Include="FluentAssertions" Version="8.4.0" />
3030
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
3131
<PackageReference Include="xunit" Version="2.9.3" />
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
// <copyright file="DeleteRestoreEnvelope.cs" company="Docusign">
2+
// Copyright (c) Docusign. All rights reserved.
3+
// </copyright>
4+
5+
namespace DocuSign.CodeExamples.ESignature.Controllers
6+
{
7+
using System.Linq;
8+
using DocuSign.CodeExamples.Common;
9+
using DocuSign.CodeExamples.Controllers;
10+
using DocuSign.CodeExamples.Models;
11+
using Microsoft.AspNetCore.Mvc;
12+
using Newtonsoft.Json;
13+
14+
[Area("eSignature")]
15+
[Route("Eg045")]
16+
public class DeleteRestoreEnvelope : EgController
17+
{
18+
private const string DeleteFolderId = "recyclebin";
19+
20+
private const string RestoreFolderId = "sentitems";
21+
22+
public DeleteRestoreEnvelope(DsConfiguration config, LauncherTexts launcherTexts, IRequestItemsService requestItemsService)
23+
: base(config, launcherTexts, requestItemsService)
24+
{
25+
this.CodeExampleText = this.GetExampleText(this.EgName, ExamplesApiType.ESignature);
26+
this.ViewBag.title = this.CodeExampleText.ExampleName;
27+
}
28+
29+
public override string EgName => "Eg045";
30+
31+
/// <summary>
32+
/// Deletes an envelope by moving it to the recycle bin.
33+
/// </summary>
34+
/// <returns>IActionResult</returns>
35+
[HttpPost]
36+
[Route("DeleteEnvelopeAction")]
37+
[SetViewBag]
38+
public IActionResult DeleteEnvelopeAction(string envelopeId)
39+
{
40+
bool tokenOk = this.CheckToken(3);
41+
42+
if (!tokenOk)
43+
{
44+
this.RequestItemsService.EgName = this.EgName;
45+
return this.Redirect("/ds/mustAuthenticate");
46+
}
47+
48+
string basePath = this.RequestItemsService.Session.BasePath + "/restapi";
49+
string accessToken = this.RequestItemsService.User.AccessToken;
50+
string accountId = this.RequestItemsService.Session.AccountId;
51+
52+
this.RequestItemsService.EnvelopeId = envelopeId;
53+
54+
global::ESignature.Examples.DeleteRestoreEnvelope.MoveEnvelopeToFolder(
55+
accessToken,
56+
basePath,
57+
accountId,
58+
envelopeId,
59+
DeleteFolderId);
60+
61+
this.ViewBag.h1 = this.CodeExampleText.ExampleName;
62+
this.ViewBag.ConfirmAdditionalLink = nameof(this.GetRestoreEnvelope);
63+
this.ViewBag.OnlyConfirmAdditionalLink = true;
64+
this.ViewBag.message = this.CodeExampleText.AdditionalPages
65+
.FirstOrDefault(x => x.Name.Equals("envelope_is_deleted"))
66+
?.ResultsPageText;
67+
68+
return this.View("example_done");
69+
}
70+
71+
/// <summary>
72+
/// Restores an envelope from the recycle bin back to the Sent Items folder.
73+
/// </summary>
74+
/// <returns>IActionResult</returns>
75+
[HttpPost]
76+
[Route("RestoreEnvelopeAction")]
77+
[SetViewBag]
78+
public IActionResult RestoreEnvelopeAction()
79+
{
80+
bool tokenOk = this.CheckToken(3);
81+
82+
if (!tokenOk)
83+
{
84+
this.RequestItemsService.EgName = this.EgName;
85+
return this.Redirect("/ds/mustAuthenticate");
86+
}
87+
88+
string basePath = this.RequestItemsService.Session.BasePath + "/restapi";
89+
string accessToken = this.RequestItemsService.User.AccessToken;
90+
string accountId = this.RequestItemsService.Session.AccountId;
91+
92+
global::ESignature.Examples.DeleteRestoreEnvelope.MoveEnvelopeToFolder(
93+
accessToken,
94+
basePath,
95+
accountId,
96+
this.RequestItemsService.EnvelopeId,
97+
RestoreFolderId,
98+
DeleteFolderId);
99+
100+
this.ViewBag.h1 = this.CodeExampleText.ExampleName;
101+
this.ViewBag.message = this.CodeExampleText.ResultsPageText;
102+
103+
return this.View("example_done");
104+
}
105+
106+
/// <summary>
107+
/// Displays a page allowing the user to restore a previously deleted envelope.
108+
/// </summary>
109+
/// <returns>ActionResult</returns>
110+
[SetViewBag]
111+
[HttpGet]
112+
[Route("GetRestoreEnvelope")]
113+
public ActionResult GetRestoreEnvelope()
114+
{
115+
this.ViewBag.CodeExampleText = this.CodeExampleText;
116+
this.ViewBag.SupportingTexts = this.LauncherTexts.ManifestStructure.SupportingTexts;
117+
this.ViewBag.EnvelopeId = this.RequestItemsService.EnvelopeId;
118+
119+
return this.View("restoreEnvelope");
120+
}
121+
122+
protected override void InitializeInternal()
123+
{
124+
base.InitializeInternal();
125+
this.ViewBag.EnvelopeId = this.RequestItemsService.EnvelopeId;
126+
}
127+
}
128+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// <copyright file="DeleteRestoreEnvelope.cs" company="Docusign">
2+
// Copyright (c) Docusign. All rights reserved.
3+
// </copyright>
4+
5+
namespace ESignature.Examples
6+
{
7+
using System.Collections.Generic;
8+
using DocuSign.eSign.Api;
9+
using DocuSign.eSign.Client;
10+
using DocuSign.eSign.Model;
11+
12+
public class DeleteRestoreEnvelope
13+
{
14+
/// <summary>
15+
/// Moves envelope to a different folder
16+
/// </summary>
17+
/// <param name="accessToken">Access Token for API call (OAuth)</param>
18+
/// <param name="basePath">BasePath for API calls (URI)</param>
19+
/// <param name="accountId">The DocuSign Account ID (GUID or short version) for which the APIs call would be made</param>
20+
/// <param name="envelopeId">Envelope ID</param>
21+
/// <param name="folderId">Folder ID</param>
22+
/// <param name="fromFolderId">From folder ID</param>
23+
/// <returns>The folders response</returns>
24+
public static FoldersResponse MoveEnvelopeToFolder(
25+
string accessToken,
26+
string basePath,
27+
string accountId,
28+
string envelopeId,
29+
string folderId,
30+
string fromFolderId = null)
31+
{
32+
var docusignClient = new DocuSignClient(basePath);
33+
docusignClient.Configuration.DefaultHeader.Add("Authorization", "Bearer " + accessToken);
34+
35+
FoldersApi foldersApi = new FoldersApi(docusignClient);
36+
var foldersRequest = new FoldersRequest
37+
{
38+
FromFolderId = fromFolderId,
39+
EnvelopeIds = new List<string> { envelopeId },
40+
};
41+
42+
return foldersApi.MoveEnvelopes(accountId, folderId, foldersRequest);
43+
}
44+
}
45+
}

launcher-csharp/eSignature/Models/ModelsToReadManifest/HelpingTexts.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,18 @@ public class HelpingTexts
2020
[JsonProperty("AccessCodeText")]
2121
public string AccessCodeText { get; set; }
2222

23+
[JsonProperty("SubmitButtonDeleteText")]
24+
public string SubmitButtonDeleteText { get; set; }
25+
26+
[JsonProperty("SubmitButtonRestoreText")]
27+
public string SubmitButtonRestoreText { get; set; }
28+
29+
[JsonProperty("EnvelopeWillBeRestored")]
30+
public string EnvelopeWillBeRestored { get; set; }
31+
32+
[JsonProperty("DefaultEnvelopeId")]
33+
public string DefaultEnvelopeId { get; set; }
34+
2335
[JsonProperty("CountryCodeText")]
2436
public string CountryCodeText { get; set; }
2537

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
@using System.Text.RegularExpressions;
2+
@{
3+
int formNumber = 0;
4+
int envelopeIdInputNumber = 0;
5+
}
6+
7+
<h4>@Html.Raw(ViewBag.CodeExampleText.ExampleName)</h4>
8+
<p>
9+
@Html.Raw(ViewBag.CodeExampleText.ExampleDescription)
10+
</p>
11+
12+
@if (ViewBag.showDoc == true)
13+
{
14+
<p><a target='_blank' href='<%= documentation %>'>Documentation</a> about this example</p>
15+
}
16+
17+
<partial name="../../../Views/Shared/LinkToMethodView" model="ViewBag.CodeExampleText" />
18+
19+
<p>
20+
@Html.Raw(
21+
@String.Format(
22+
ViewBag.SupportingTexts.ViewSourceFile,
23+
"<a target='_blank' href=" + @ViewBag.source + ">DeleteRestoreEnvelope.cs</a>"
24+
)
25+
)
26+
</p>
27+
28+
<form class="eg" asp-area="eSignature" asp-controller="DeleteRestoreEnvelope" asp-action="DeleteEnvelopeAction" data-busy="form">
29+
<div class="form-group">
30+
<label for="envelopeId">
31+
@Html.Raw(ViewBag.CodeExampleText.Forms[formNumber].Inputs[envelopeIdInputNumber].InputName)
32+
</label>
33+
34+
<input type="text"
35+
class="form-control"
36+
id="envelopeId"
37+
name="envelopeId"
38+
placeholder="@ViewBag.CodeExampleText.Forms[formNumber].Inputs[envelopeIdInputNumber].InputPlaceholder"
39+
required
40+
value="@ViewBag.EnvelopeId">
41+
42+
<small id="envelopeIdHelp" class="form-text text-muted">@Html.Raw(ViewBag.SupportingTexts.HelpingTexts.DefaultEnvelopeId)</small>
43+
</div>
44+
45+
<button type="submit" class="btn btn-primary">
46+
@Html.Raw(ViewBag.SupportingTexts.HelpingTexts.SubmitButtonDeleteText)
47+
</button>
48+
</form>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<h4>@Html.Raw(ViewBag.CodeExampleText.ExampleName)</h4>
2+
<p>
3+
@Html.Raw(ViewBag.CodeExampleText.ExampleDescription)
4+
</p>
5+
6+
7+
<p>
8+
@Html.Raw(string.Format(ViewBag.SupportingTexts.HelpingTexts.EnvelopeWillBeRestored, ViewBag.EnvelopeId))
9+
</p>
10+
11+
<form class="eg" asp-area="eSignature" asp-controller="DeleteRestoreEnvelope" asp-action="RestoreEnvelopeAction" method="post" data-busy="form">
12+
<button type="submit" class="btn btn-primary">
13+
@Html.Raw(ViewBag.SupportingTexts.HelpingTexts.SubmitButtonRestoreText)
14+
</button>
15+
</form>

launcher-csharp/launcher-csharp.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
<ItemGroup>
3939
<PackageReference Include="DocuSign.Admin" Version="2.0.2" />
4040
<PackageReference Include="DocuSign.Click" Version="2.0.2" />
41-
<PackageReference Include="DocuSign.eSign.dll" Version="8.2.0" />
41+
<PackageReference Include="DocuSign.eSign.dll" Version="8.4.0" />
4242
<PackageReference Include="DocuSign.Monitor" Version="2.0.2" />
4343
<PackageReference Include="DocuSign.Rooms" Version="2.0.2" />
4444
<PackageReference Include="DocuSign.WebForms" Version="3.1.0" />

manifest/CodeExamplesManifest.json

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@
3939
"AGREED": "AGREED",
4040
"SaveAgentActivationCode": "Save this code. You'll need it when activating the new agent.",
4141
"EmailAddressOfUserToDelete": "The email address of the user whose data will be deleted. Note that this email address should be associated with a user that has been closed for 24 hours.",
42-
"UserIDOfUserToDelete": "The user ID of the user whose data will be deleted. Note that this ID should be associated with a user that has been closed for 24 hours."
42+
"UserIDOfUserToDelete": "The user ID of the user whose data will be deleted. Note that this ID should be associated with a user that has been closed for 24 hours.",
43+
"SubmitButtonDeleteText": "Delete",
44+
"SubmitButtonRestoreText": "Restore",
45+
"DefaultEnvelopeId": "If example 2 was executed, the envelope ID saved after it will be used by default. Alternatively, a different ID can be specified.",
46+
"EnvelopeWillBeRestored": "Envelope {0} will be restored."
4347
}
4448
},
4549
"APIs": [
@@ -1685,6 +1689,36 @@
16851689
"ResultsPageText": "NDSE view URL: {0}."
16861690
}
16871691
]
1692+
},
1693+
{
1694+
"ExampleNumber": 45,
1695+
"CFREnabled": "NonCFR",
1696+
"ExampleName": "Delete and Restore an Envelope",
1697+
"ExampleDescription": "Moves an Envelope to a recycling bin. Then restores it by moving it to the Sent folder.",
1698+
"Notes": "<b>Note:</b> To know your envelope ID, see <a target='_blank' href=\"https://support.docusign.com/s/articles/Where-do-I-find-my-envelope-ID\">Locate a Docusign envelope ID</a>.",
1699+
"LinksToAPIMethod": [
1700+
{
1701+
"Path": "https://developers.docusign.com/docs/esign-rest-api/reference/folders/folders/moveenvelopes/",
1702+
"PathName": "Folders:moveEnvelopes"
1703+
}
1704+
],
1705+
"Forms": [
1706+
{
1707+
"Inputs": [
1708+
{
1709+
"InputName": "Envelope ID",
1710+
"InputPlaceholder": "12345678-1234-1234-1234-123456789012"
1711+
}
1712+
]
1713+
}
1714+
],
1715+
"ResultsPageText": "Envelope is restored to the <a target='_blank' href=\"https://apps-d.docusign.com/send/documents?view=sent\">Sent</a> folder",
1716+
"AdditionalPage": [
1717+
{
1718+
"Name": "envelope_is_deleted",
1719+
"ResultsPageText": "Envelope is deleted and available in the <a target='_blank' href=\"https://apps-d.docusign.com/send/documents?view=deleted\">Deleted</a> folder."
1720+
}
1721+
]
16881722
}
16891723
]
16901724
},

0 commit comments

Comments
 (0)