-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathExecTest.cs
More file actions
162 lines (111 loc) · 5.32 KB
/
ExecTest.cs
File metadata and controls
162 lines (111 loc) · 5.32 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
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
public class ExecTest
{
public static void CreateAccount(string token, string urlBase)
{
WebApi webApi = new WebApi();
var account1 = new account
{
accountnumber = "ERP010",
name = "María González Rodríguez",
exchangerate = 1.25m,
emailaddress1 = "contacto@tecinnova.com",
telephone1 = "+502-2234-5678",
address1_country = "Guatemala",
address1_postalcode = "01001",
creditlimit = 50000.00m,
paymenttermscode = 1,
creditonhold = false
,
TransactionCurrencyId = "GTQ"
};
string currencyId = Task.Run(async () => await webApi.getCurrency(account1.TransactionCurrencyId, token, urlBase)).GetAwaiter().GetResult();
account1.TransactionCurrencyId = $"/transactioncurrencies({currencyId})"; // Set the lookup reference for transactioncurrencyid
Task.Run(async () => webApi.CreateAccount(account1, token, urlBase)).GetAwaiter().GetResult();
}
public static void UpdateAccount(string token, string urlBase)
{
WebApi webApi = new WebApi();
var account1 = new account
{
accountnumber = "ERP010",
name = "María González Rodríguez",
exchangerate = 1.25m,
emailaddress1 = "maria.gonzalez@email.com",
telephone1 = "+502-5321-4571",
address1_country = "Guatemala",
address1_postalcode = "01001",
creditlimit = 50000.00m,
paymenttermscode = 1,
creditonhold = false,
TransactionCurrencyId = "GTQ"
};
string currencyId = Task.Run(async () => await webApi.getCurrency(account1.TransactionCurrencyId, token, urlBase)).GetAwaiter().GetResult();
account1.TransactionCurrencyId = $"/transactioncurrencies({currencyId})"; // Set the lookup reference for transactioncurrencyid
string accountId = Task.Run(async () => await webApi.getAccountId(account1.accountnumber, token, urlBase)).GetAwaiter().GetResult();
account1.accountid = accountId; // Set the accountid for the update
webApi.UpdateAccount(account1, token, urlBase).GetAwaiter().GetResult();
}
public static void DeleteAccount(string token, string urlBase)
{
WebApi webApi = new WebApi();
var account1 = new account
{
accountnumber = "ERP010"
};
string accountId = Task.Run(async () => await webApi.getAccountId(account1.accountnumber, token, urlBase)).GetAwaiter().GetResult();
account1.accountid = accountId; // Set the accountid for the update
webApi.DeleteAccount(account1, token, urlBase).GetAwaiter().GetResult();
}
public static void getAccountId(string token, string urlBase)
{
WebApi webApi = new WebApi();
var account = Task.Run(async () => await webApi.GetAccountById("0bcd05d2-45a9-f011-bbd3-000d3a34f71c", token, urlBase)).GetAwaiter().GetResult();
Console.WriteLine($"El ID de la cuenta buscada : {account.accountid}, Nombre: {account.name}, Número de cuenta: {account.accountnumber}");
}
public static void GetAccounts(string token, string urlBase)
{
WebApi webApi = new WebApi();
// Ejemplo de select y filter OData
string selectOData = "accountnumber,name,accountid";
string filterOData = "startswith(accountnumber,'ERP')";
// Llama a la función GetAccounts con los parámetros adecuados
var accounts = Task.Run(async () => await webApi.GetAccounts(selectOData, filterOData, token, urlBase)).GetAwaiter().GetResult();
if (accounts != null && accounts.Count > 0)
{
foreach (var acc in accounts)
{
Console.WriteLine($"Account Number: {acc.accountnumber}, Name: {acc.name}, ID: {acc.accountid}");
}
}
else
{
Console.WriteLine("No se encontraron cuentas.");
}
}
public static void getFetchXML(string token, string urlBase)
{
WebApi webApi = new WebApi();
var fetchXml = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
<entity name='account'>
<attribute name='accountnumber' />
<attribute name='name' />
<attribute name='accountid' />
<attribute name='transactioncurrencyid' />
<link-entity name='transactioncurrency' from='transactioncurrencyid' to='transactioncurrencyid' alias='currency' link-type='inner'>
<attribute name='isocurrencycode' />
<attribute name='currencysymbol' />
</link-entity>
<order attribute='name' descending='false' />
</entity>
</fetch>";
Task.Run(async () => await webApi.GetFetchXML(fetchXml, token, urlBase)).GetAwaiter().GetResult();
}
public static void createSalesOrder(string token, string urlBase)
{
string priceLevelId = "bddd2189-a0aa-f011-bbd3-000d3a5ba373";
string currencyId = "16d81bf0-21a9-f011-bbd3-000d3a5ba373";
var salesOrderApi = new WebApiSalesOrder(priceLevelId, currencyId);
var accounts = Task.Run(async() => await salesOrderApi.GetAccountsByCurrency(token, urlBase)).GetAwaiter().GetResult();
Task.Run(async() => await salesOrderApi.CreateSalesOrder(token, urlBase, accounts)).GetAwaiter().GetResult();
}
}