forked from EncompassRest/EncompassRest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDocuments.cs
119 lines (99 loc) · 4.06 KB
/
Documents.cs
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
using EncompassREST.Data;
using EncompassREST.LoanDocs;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
namespace EncompassREST
{
public class Documents
{
private Loan _loan;
public Session Session
{
get { return _loan.Session; }
}
public Documents(Loan Loan)
{
_loan = Loan;
}
public async Task<List<Document>> getDocumentsListAsync()
{
HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Get, string.Format("loans/{0}/documents", _loan.encompassId));
var response = await Session.RESTClient.SendAsync(message);
if (response.IsSuccessStatusCode)
{
return JsonConvert.DeserializeObject<List<Document>>(await response.Content.ReadAsStringAsync());
}
else
{
throw new EncompassREST.Exceptions.RESTException("getDocuments", response);
}
}
public async Task<Document> getDocumentAsync(string DocumentID)
{
HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Get, string.Format("loans/{0}/documents/{1}", _loan.encompassId,DocumentID));
var response = await Session.RESTClient.SendAsync(message);
if (response.IsSuccessStatusCode)
{
return JsonConvert.DeserializeObject<Document>(await response.Content.ReadAsStringAsync());
}
else
{
throw new EncompassREST.Exceptions.RESTException("getDocuments", response);
}
}
public async Task<List<Attachment>> getDocumentAttachmentListAsync(string DocumentID)
{
HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Get, string.Format("loans/{0}/documents/{1}/attachments", _loan.encompassId, DocumentID));
var response = await Session.RESTClient.SendAsync(message);
if (response.IsSuccessStatusCode)
{
return JsonConvert.DeserializeObject<List<Attachment>>(await response.Content.ReadAsStringAsync());
}
else
{
throw new EncompassREST.Exceptions.RESTException("getDocuments", response);
}
}
public async Task<Document> postDocument(string title,string applicationId = "All")
{
var newDoc = new
{
title = title,
applicationId = applicationId,
entityId = 1,
entityType = "document"
};
HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Post, string.Format("loans/{0}/documents", _loan.encompassId));
message.Content = new StringContent(JsonConvert.SerializeObject(newDoc), Encoding.UTF32, "application/json");
var response = await Session.RESTClient.SendAsync(message);
if (response.IsSuccessStatusCode)
{
var ID = response.Headers.Location.Segments.Last();
return await getDocumentAsync(ID);
}
else
{
throw new EncompassREST.Exceptions.RESTException("getDocuments", response);
}
}
public async Task<string> getDownloadUrlAsync(Attachment attachment)
{
HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Post, string.Format("loans/{0}/attachments/{1}/url", _loan.encompassId,attachment.entityId));
var response = await Session.RESTClient.SendAsync(message);
if (response.IsSuccessStatusCode)
{
var mu = JsonConvert.DeserializeObject<MediaURL>(await response.Content.ReadAsStringAsync());
return mu.mediaUrl;
}
else
{
throw new EncompassREST.Exceptions.RESTException("getDownloadUrlAsync", response);
}
}
}
}