-
Notifications
You must be signed in to change notification settings - Fork 0
/
Exercise02ListAccounts.cs
85 lines (65 loc) · 3.3 KB
/
Exercise02ListAccounts.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ParatureSDK;
using ParatureSDK.ParaObjects;
namespace Exercises
{
class Exercise02ListAccounts
{
//List all of the accounts
public static ParaEntityList<ParatureSDK.ParaObjects.Account> getAllAccounts()
{
//Query object is a query string builder
var accountQuery = new ParatureSDK.ModuleQuery.AccountQuery();
accountQuery.RetrieveAllRecords = true; //Retrieve all records will maximize page size and make necessary additional calls to retrieve all pages
var accounts = ParatureSDK.ApiHandler.Account.GetList(CredentialProvider.Creds, accountQuery);
var apiResponse = accounts.ApiCallResponse; //API response is provided with object
if (apiResponse.HasException)
{
//Exception handling is a best practice
Console.Write(apiResponse.ExceptionDetails);
return null;
}
return accounts;
}
public static ParaEntityList<ParatureSDK.ParaObjects.Account> searchAccountsByName(string accountName)
{
var accountQuery = new ParatureSDK.ModuleQuery.AccountQuery();
accountQuery.RetrieveAllRecords = true;
//There is a difference between static fields and custom fields
accountQuery.AddStaticFieldFilter(ParatureSDK.ModuleQuery.AccountQuery.AccountStaticFields.Accountname, ParatureSDK.ParaEnums.QueryCriteria.Equal, accountName);
var accounts = ParatureSDK.ApiHandler.Account.GetList(CredentialProvider.Creds, accountQuery);
return accounts;
}
public static ParaEntityList<ParatureSDK.ParaObjects.Account> searchAccountsByField(long fieldID, string fieldValue)
{
var accountQuery = new ParatureSDK.ModuleQuery.AccountQuery();
accountQuery.RetrieveAllRecords = true;
accountQuery.AddCustomFieldFilter(fieldID, ParatureSDK.ParaEnums.QueryCriteria.Equal, fieldValue);
var accounts = ParatureSDK.ApiHandler.Account.GetList(CredentialProvider.Creds, accountQuery);
return accounts;
}
//Overload for an option field
public static ParaEntityList<ParatureSDK.ParaObjects.Account> searchAccountsByField(long fieldID, long fieldValue)
{
//field value would be option ID
var accountQuery = new ParatureSDK.ModuleQuery.AccountQuery();
accountQuery.RetrieveAllRecords = true;
accountQuery.AddCustomFieldFilter(fieldID, ParaEnums.QueryCriteria.Equal, fieldValue);
var accounts = ParatureSDK.ApiHandler.Account.GetList(CredentialProvider.Creds, accountQuery);
return accounts;
}
public static ParaEntityList<ParatureSDK.ParaObjects.Account> getAccountsByView(long viewID)
{
//field value would be option ID
var accountQuery = new ParatureSDK.ModuleQuery.AccountQuery();
accountQuery.RetrieveAllRecords = true;
accountQuery.View = viewID;
var accounts = ParatureSDK.ApiHandler.Account.GetList(CredentialProvider.Creds, accountQuery);
return accounts;
}
}
}