forked from docusign/code-examples-csharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEg05GetRoomsWithFiltersController.cs
More file actions
81 lines (69 loc) · 3.21 KB
/
Eg05GetRoomsWithFiltersController.cs
File metadata and controls
81 lines (69 loc) · 3.21 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
77
78
79
80
81
using System.Globalization;
using DocuSign.CodeExamples.Common;
using DocuSign.CodeExamples.Controllers;
using DocuSign.CodeExamples.Models;
using DocuSign.CodeExamples.Rooms.Models;
using DocuSign.Rooms.Api;
using DocuSign.Rooms.Client;
using DocuSign.Rooms.Model;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
namespace DocuSign.CodeExamples.Rooms.Controllers
{
[Area("Rooms")]
[Route("Eg05")]
public class Eg05GetRoomsWithFiltersController : EgController
{
public Eg05GetRoomsWithFiltersController(
DSConfiguration dsConfig,
IRequestItemsService requestItemsService) : base(dsConfig, requestItemsService)
{
}
public override string EgName => "Eg05";
[BindProperty]
public RoomFilterModel RoomFilterModel { get; set; }
protected override void InitializeInternal()
{
RoomFilterModel = new RoomFilterModel();
}
[MustAuthenticate]
[Route("ExportData")]
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult ExportData(RoomFilterModel roomFilterModel)
{
// Step 1. Obtain your OAuth token
string accessToken = RequestItemsService.User.AccessToken; // Represents your {ACCESS_TOKEN}
var basePath = $"{RequestItemsService.Session.RoomsApiBasePath}/restapi"; // Base API path
// Step 2: Construct your API headers
var apiClient = new ApiClient(basePath);
apiClient.Configuration.DefaultHeader.Add("Authorization", "Bearer " + accessToken);
var roomsApi = new RoomsApi(apiClient);
string accountId = RequestItemsService.Session.AccountId; // Represents your {ACCOUNT_ID}
try
{
// Step 3: Prepare your request parameters
var fieldDataChangedStartDate = roomFilterModel.FieldDataChangedStartDate.ToString(CultureInfo.InvariantCulture);
var fieldDataChangedEndDate = roomFilterModel.FieldDataChangedEndDate.ToString(CultureInfo.InvariantCulture);
// Step 4: Call the Rooms API to get rooms with filters
RoomSummaryList rooms = roomsApi.GetRooms(accountId, new RoomsApi.GetRoomsOptions
{
fieldDataChangedStartDate = fieldDataChangedStartDate,
fieldDataChangedEndDate = fieldDataChangedEndDate
});
ViewBag.h1 = "The rooms with filters was loaded";
ViewBag.message = $"Results from the Rooms: GetRooms method. FieldDataChangedStartDate: " +
$"{ roomFilterModel.FieldDataChangedStartDate.Date.ToShortDateString() }, " +
$"FieldDataChangedEndDate: { roomFilterModel.FieldDataChangedEndDate.Date.ToShortDateString() } :";
ViewBag.Locals.Json = JsonConvert.SerializeObject(rooms, Formatting.Indented);
return View("example_done");
}
catch (ApiException apiException)
{
ViewBag.errorCode = apiException.ErrorCode;
ViewBag.errorMessage = apiException.Message;
return View("Error");
}
}
}
}