Skip to content

Commit 89341dd

Browse files
author
Balaji Jayaraman
committed
added code snippets for delete and restore envelope
1 parent 34b3b9e commit 89341dd

File tree

14 files changed

+445
-26
lines changed

14 files changed

+445
-26
lines changed

DSHelper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// <copyright file="DSHelper.cs" company="DocuSign">
2-
// Copyright (c) DocuSign. All rights reserved.
1+
// <copyright file="DSHelper.cs" company="Docusign">
2+
// Copyright (c) Docusign. All rights reserved.
33
// </copyright>
44

55
namespace DocuSign.CodeExamples.Common

ExamplesAPIType.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// <copyright file="ExamplesAPIType.cs" company="DocuSign">
2-
// Copyright (c) DocuSign. All rights reserved.
1+
// <copyright file="ExamplesAPIType.cs" company="Docusign">
2+
// Copyright (c) Docusign. All rights reserved.
33
// </copyright>
44

55
namespace DocuSign.CodeExamples.Common
@@ -61,7 +61,7 @@ public enum ExamplesApiType
6161
/// </summary>")]
6262
[Description("nav")]
6363
Navigator = 8,
64-
64+
6565
/// <summary>
6666
/// Maestro
6767
/// </summary>")]

ExamplesApiTypeExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// <copyright file="ExamplesApiTypeExtensions.cs" company="DocuSign">
2-
// Copyright (c) DocuSign. All rights reserved.
1+
// <copyright file="ExamplesApiTypeExtensions.cs" company="Docusign">
2+
// Copyright (c) Docusign. All rights reserved.
33
// </copyright>
44

55
namespace DocuSign.CodeExamples.Common

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.1.0-rc" />
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>

JWTAuth.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// <copyright file="JWTAuth.cs" company="DocuSign">
2-
// Copyright (c) DocuSign. All rights reserved.
1+
// <copyright file="JWTAuth.cs" company="Docusign">
2+
// Copyright (c) Docusign. All rights reserved.
33
// </copyright>
44

55
namespace DocuSign.CodeExamples.Authentication

Quick_ACG/Quick_ACG.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@
4747
</ItemGroup>
4848

4949
<ItemGroup>
50-
<PackageReference Include="DocuSign.Admin" Version="2.0.0" />
51-
<PackageReference Include="DocuSign.eSign.dll" Version="8.1.0-rc" />
52-
<PackageReference Include="Microsoft.AspNetCore.Session" Version="2.2.0" />
50+
<PackageReference Include="DocuSign.Admin" Version="2.0.2" />
51+
<PackageReference Include="DocuSign.eSign.dll" Version="8.4.0" />
52+
<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">
5555
<PrivateAssets>all</PrivateAssets>

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@
2424
</ItemGroup>
2525

2626
<ItemGroup>
27-
<PackageReference Include="DocuSign.Admin" Version="2.0.0-rc4" />
28-
<PackageReference Include="DocuSign.eSign.dll" Version="8.1.0-rc" />
29-
<PackageReference Include="FluentAssertions" Version="6.12.0" />
27+
<PackageReference Include="DocuSign.Admin" Version="2.0.2" />
28+
<PackageReference Include="DocuSign.eSign.dll" Version="8.4.0" />
29+
<PackageReference Include="FluentAssertions" Version="8.4.0" />
3030
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
31-
<PackageReference Include="xunit" Version="2.9.0" />
32-
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
31+
<PackageReference Include="xunit" Version="2.9.3" />
32+
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.1">
3333
<PrivateAssets>all</PrivateAssets>
3434
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
3535
</PackageReference>
36-
<PackageReference Include="coverlet.collector" Version="6.0.2">
36+
<PackageReference Include="coverlet.collector" Version="6.0.4">
3737
<PrivateAssets>all</PrivateAssets>
3838
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
3939
</PackageReference>
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
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 DocuSign.eSign.Model;
12+
using Microsoft.AspNetCore.Mvc;
13+
using Newtonsoft.Json;
14+
15+
[Area("eSignature")]
16+
[Route("Eg045")]
17+
public class DeleteRestoreEnvelope : EgController
18+
{
19+
private const string DeleteFolderId = "recyclebin";
20+
21+
private const string SentItemsFolderName = "Sent Items";
22+
23+
public DeleteRestoreEnvelope(DsConfiguration config, LauncherTexts launcherTexts, IRequestItemsService requestItemsService)
24+
: base(config, launcherTexts, requestItemsService)
25+
{
26+
this.CodeExampleText = this.GetExampleText(this.EgName, ExamplesApiType.ESignature);
27+
this.ViewBag.title = this.CodeExampleText.ExampleName;
28+
}
29+
30+
public override string EgName => "Eg045";
31+
32+
/// <summary>
33+
/// Deletes an envelope by moving it to the recycle bin.
34+
/// </summary>
35+
/// <returns>IActionResult</returns>
36+
[HttpPost]
37+
[Route("DeleteEnvelopeAction")]
38+
[SetViewBag]
39+
public IActionResult DeleteEnvelopeAction(string envelopeId)
40+
{
41+
bool tokenOk = this.CheckToken(3);
42+
43+
if (!tokenOk)
44+
{
45+
this.RequestItemsService.EgName = this.EgName;
46+
return this.Redirect("/ds/mustAuthenticate");
47+
}
48+
49+
string basePath = this.RequestItemsService.Session.BasePath + "/restapi";
50+
string accessToken = this.RequestItemsService.User.AccessToken;
51+
string accountId = this.RequestItemsService.Session.AccountId;
52+
53+
this.RequestItemsService.EnvelopeId = envelopeId;
54+
55+
global::ESignature.Examples.DeleteRestoreEnvelope.DeleteEnvelope(
56+
accessToken,
57+
basePath,
58+
accountId,
59+
envelopeId);
60+
61+
this.ViewBag.h1 = this.CodeExampleText.ExampleName;
62+
this.ViewBag.ConfirmAdditionalLink = nameof(this.GetRestoreEnvelope);
63+
this.ViewBag.OnlyConfirmAdditionalLink = true;
64+
this.ViewBag.message = string.Format(
65+
this.CodeExampleText.AdditionalPages
66+
.FirstOrDefault(x => x.Name.Equals("envelope_is_deleted"))
67+
?.ResultsPageText,
68+
envelopeId);
69+
70+
return this.View("example_done");
71+
}
72+
73+
/// <summary>
74+
/// Restores an envelope from the recycle bin back to the Sent Items folder.
75+
/// </summary>
76+
/// <returns>IActionResult</returns>
77+
[HttpPost]
78+
[Route("RestoreEnvelopeAction")]
79+
[SetViewBag]
80+
public IActionResult RestoreEnvelopeAction(string folderName)
81+
{
82+
bool tokenOk = this.CheckToken(3);
83+
folderName = folderName ?? SentItemsFolderName;
84+
85+
if (!tokenOk)
86+
{
87+
this.RequestItemsService.EgName = this.EgName;
88+
return this.Redirect("/ds/mustAuthenticate");
89+
}
90+
91+
string basePath = this.RequestItemsService.Session.BasePath + "/restapi";
92+
string accessToken = this.RequestItemsService.User.AccessToken;
93+
string accountId = this.RequestItemsService.Session.AccountId;
94+
95+
FoldersResponse availableFolders = global::ESignature.Examples.DeleteRestoreEnvelope.GetFolders(
96+
accessToken,
97+
basePath,
98+
accountId);
99+
Folder folder = global::ESignature.Examples.DeleteRestoreEnvelope.GetFolderByName(
100+
availableFolders.Folders,
101+
folderName);
102+
103+
if (folder == null)
104+
{
105+
this.ViewBag.h1 = this.CodeExampleText.ExampleName;
106+
this.ViewBag.message = string.Format(this.CodeExampleText.AdditionalPages[1].ResultsPageText, folderName);
107+
this.ViewBag.ConfirmAdditionalLink = nameof(this.GetRestoreEnvelope);
108+
this.ViewBag.OnlyConfirmAdditionalLink = true;
109+
110+
return this.View("example_done");
111+
}
112+
113+
global::ESignature.Examples.DeleteRestoreEnvelope.MoveEnvelopeToFolder(
114+
accessToken,
115+
basePath,
116+
accountId,
117+
this.RequestItemsService.EnvelopeId,
118+
folder.FolderId,
119+
DeleteFolderId);
120+
121+
this.ViewBag.h1 = this.CodeExampleText.ExampleName;
122+
this.ViewBag.message = string.Format(
123+
this.CodeExampleText.ResultsPageText,
124+
this.RequestItemsService.EnvelopeId,
125+
folder.Type,
126+
folderName);
127+
128+
return this.View("example_done");
129+
}
130+
131+
/// <summary>
132+
/// Displays a page allowing the user to restore a previously deleted envelope.
133+
/// </summary>
134+
/// <returns>ActionResult</returns>
135+
[SetViewBag]
136+
[HttpGet]
137+
[Route("GetRestoreEnvelope")]
138+
public ActionResult GetRestoreEnvelope()
139+
{
140+
this.ViewBag.CodeExampleText = this.CodeExampleText;
141+
this.ViewBag.SupportingTexts = this.LauncherTexts.ManifestStructure.SupportingTexts;
142+
this.ViewBag.EnvelopeId = this.RequestItemsService.EnvelopeId;
143+
144+
return this.View("restoreEnvelope");
145+
}
146+
147+
protected override void InitializeInternal()
148+
{
149+
base.InitializeInternal();
150+
this.ViewBag.EnvelopeId = this.RequestItemsService.EnvelopeId;
151+
}
152+
}
153+
}
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
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+
private const string DeleteFolderId = "recyclebin";
15+
16+
/// <summary>
17+
/// Delete envelope
18+
/// </summary>
19+
/// <param name="accessToken">Access Token for API call (OAuth)</param>
20+
/// <param name="basePath">BasePath for API calls (URI)</param>
21+
/// <param name="accountId">The DocuSign Account ID (GUID or short version) for which the APIs call would be made</param>
22+
/// <param name="envelopeId">Envelope ID</param>
23+
/// <returns>The folders response</returns>
24+
public static FoldersResponse DeleteEnvelope(
25+
string accessToken,
26+
string basePath,
27+
string accountId,
28+
string envelopeId)
29+
{
30+
//ds-snippet-start:eSign45Step2
31+
var docusignClient = new DocuSignClient(basePath);
32+
docusignClient.Configuration.DefaultHeader.Add("Authorization", "Bearer " + accessToken);
33+
//ds-snippet-end:eSign45Step2
34+
35+
FoldersApi foldersApi = new FoldersApi(docusignClient);
36+
//ds-snippet-start:eSign45Step3
37+
var foldersRequest = new FoldersRequest
38+
{
39+
EnvelopeIds = new List<string> { envelopeId },
40+
};
41+
//ds-snippet-end:eSign45Step3
42+
//ds-snippet-start:eSign45Step4
43+
return foldersApi.MoveEnvelopes(accountId, DeleteFolderId, foldersRequest);
44+
//ds-snippet-end:eSign45Step4
45+
}
46+
47+
/// <summary>
48+
/// Moves envelope to a different folder
49+
/// </summary>
50+
/// <param name="accessToken">Access Token for API call (OAuth)</param>
51+
/// <param name="basePath">BasePath for API calls (URI)</param>
52+
/// <param name="accountId">The DocuSign Account ID (GUID or short version) for which the APIs call would be made</param>
53+
/// <param name="envelopeId">Envelope ID</param>
54+
/// <param name="folderId">Folder ID</param>
55+
/// <param name="fromFolderId">From folder ID</param>
56+
/// <returns>The folders response</returns>
57+
public static FoldersResponse MoveEnvelopeToFolder(
58+
string accessToken,
59+
string basePath,
60+
string accountId,
61+
string envelopeId,
62+
string folderId,
63+
string fromFolderId = null)
64+
{
65+
var docusignClient = new DocuSignClient(basePath);
66+
docusignClient.Configuration.DefaultHeader.Add("Authorization", "Bearer " + accessToken);
67+
68+
FoldersApi foldersApi = new FoldersApi(docusignClient);
69+
var foldersRequest = new FoldersRequest
70+
{
71+
FromFolderId = fromFolderId,
72+
EnvelopeIds = new List<string> { envelopeId },
73+
};
74+
75+
//ds-snippet-start:eSign45Step6
76+
return foldersApi.MoveEnvelopes(accountId, folderId, foldersRequest);
77+
//ds-snippet-end:eSign45Step6
78+
}
79+
80+
/// <summary>
81+
/// Gets the list of folders
82+
/// </summary>
83+
/// <param name="accessToken">Access Token for API call (OAuth)</param>
84+
/// <param name="basePath">BasePath for API calls (URI)</param>
85+
/// <param name="accountId">The DocuSign Account ID (GUID or short version) for which the APIs call would be made</param>
86+
/// <returns>The folders response</returns>
87+
public static FoldersResponse GetFolders(
88+
string accessToken,
89+
string basePath,
90+
string accountId)
91+
{
92+
var docusignClient = new DocuSignClient(basePath);
93+
docusignClient.Configuration.DefaultHeader.Add("Authorization", "Bearer " + accessToken);
94+
95+
FoldersApi foldersApi = new FoldersApi(docusignClient);
96+
return foldersApi.List(accountId);
97+
}
98+
99+
/// <summary>
100+
/// Gets folder by name
101+
/// </summary>
102+
/// <param name="folders">List of folders to search</param>
103+
/// <param name="targetName">Name of the folder to find</param>
104+
/// <returns>The folder</returns>
105+
public static Folder GetFolderByName(List<Folder> folders, string targetName)
106+
{
107+
foreach (Folder folder in folders)
108+
{
109+
if (folder.Name.Equals(targetName))
110+
{
111+
return folder;
112+
}
113+
114+
//ds-snippet-start:eSign45Step5
115+
if (folder.Folders != null && !folder.Folders.Count.Equals(0))
116+
{
117+
Folder nestedFolder = GetFolderByName(folder.Folders, targetName);
118+
if (nestedFolder != null)
119+
{
120+
return nestedFolder;
121+
}
122+
}
123+
124+
//ds-snippet-end:eSign45Step5
125+
}
126+
127+
return null;
128+
}
129+
}
130+
}

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

0 commit comments

Comments
 (0)