-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram.cs
More file actions
70 lines (61 loc) · 2.15 KB
/
Program.cs
File metadata and controls
70 lines (61 loc) · 2.15 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
using PayrollEngine.Client.Model;
using PayrollEngine.Client.Service.Api;
using Task = System.Threading.Tasks.Task;
namespace PayrollEngine.Client.Tutorial.ClientObjectsAndServices;
/// <summary>The client objects and services tutorial program</summary>
internal class Program : ConsoleProgram<Program>
{
/// <inheritdoc />
protected override async Task RunAsync()
{
// tenant argument
var tenantIdentifier = ConsoleArguments.Get(1);
if (string.IsNullOrWhiteSpace(tenantIdentifier))
{
WriteErrorLine("Missing argument tenant identifier.");
PressAnyKey();
return;
}
// tenant request
var tenantService = new TenantService(HttpClient);
var tenant = await tenantService.GetAsync<Tenant>(new(), tenantIdentifier);
if (tenant == null)
{
WriteErrorLine($"Invalid tenant identifier {tenantIdentifier}.");
PressAnyKey();
return;
}
// employee query
DivisionQuery query = new()
{
// list order
OrderBy = $"{nameof(Employee.FirstName)} DESC",
// name filter example (OData)
//Filter = $"Contains({nameof(Employee.LastName)}, 'a')",
// top argument
Top = ConsoleArguments.GetInt(2)
};
// employees request
var employeeService = new EmployeeService(HttpClient);
var employees = await employeeService.QueryAsync<Employee>(new(tenant.Id), query);
// employee list
WriteTitleLine($"{tenantIdentifier} employees");
foreach (var employee in employees)
{
WriteLine($"{employee.FirstName} {employee.LastName} - {employee.Identifier} [#{employee.Id}]");
}
WriteLine();
WriteSuccessLine($"Total {employees.Count} employees");
WriteLine();
PressAnyKey();
}
/// <summary>Program entry point</summary>
static async Task Main()
{
// init logger
Log.SetLogger(new Serilog.PayrollLog());
// execute program
using var program = new Program();
await program.ExecuteAsync();
}
}