-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOrdersRepository.cs
More file actions
41 lines (35 loc) · 1.06 KB
/
OrdersRepository.cs
File metadata and controls
41 lines (35 loc) · 1.06 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
using OrdersApi.Dtos;
public sealed class OrdersRepository
{
private readonly PgDb _db;
public OrdersRepository(PgDb db)
{
_db = db;
}
public async Task<List<OrderDto>> GetAllAsync()
{
const string sql = """
SELECT id, customer_id, order_date, order_type_id, total_amount
FROM orders
ORDER BY id;
""";
await using var cmd = _db.CreateCommand(sql);
await using var reader = await cmd.ExecuteReaderAsync();
var results = new List<OrderDto>();
while (await reader.ReadAsync())
{
results.Add(new OrderDto
{
OrderId = reader.GetInt32(0),
CustomerId = reader.GetInt32(1),
OrderDate = reader.GetDateTime(2),
order_type_id = reader.GetInt32(3),
OrderAmount = reader.GetInt32(4),
CustomerName = string.Empty,
DimensonCode = string.Empty,
RunningTotal = 0
});
}
return results;
}
}