|
| 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 | +} |
0 commit comments