-
Notifications
You must be signed in to change notification settings - Fork 0
/
Core.cs
107 lines (90 loc) · 3.23 KB
/
Core.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
using DateTimeConversion.Models;
namespace DateTimeConversion
{
internal class Core : ICore
{
private readonly AccountDbContext _dbContext;
public Core(AccountDbContext dbContext)
{
_dbContext = dbContext;
}
public async Task RunTasksAsync()
{
//seed data
try
{
await SeedData();
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
DateTime dateTime = Convert.ToDateTime("2022-07-07").ToUniversalTime().Date;
GetData(dateTime);
DateTime dateTime1 = DateTime.UtcNow.AddHours(1).Date;
GetData(dateTime1);
}
private void GetData(DateTime transactionDate)
{
//get data using today as Date
int numToSkip = 0;
int pageSize = 10;
var transactions = _dbContext.AccountTransactions
.Where(transaction => transaction.TransactionDate.Date == transactionDate.Date)
.OrderByDescending(transaction => transaction.TransactionDate)
.Skip(numToSkip)
.Take(pageSize);
Console.WriteLine(transactions.Count());
}
private async Task SeedData()
{
if (_dbContext.AccountTransactions.Count() > 0)
{
return;
}
Guid accountId = Guid.NewGuid();
List<AccountTransaction> accountTransactions = new List<AccountTransaction>
{
new AccountTransaction
{
AccountId = accountId,
TransactionId = Guid.NewGuid(),
DateCreated = DateTime.UtcNow,
DateUpdated = DateTime.UtcNow,
TransactionDate = DateTime.UtcNow,
Amount = 1000,
Balance = 10000,
TransactionStatus = 1,
TransactionType = 1
},
new AccountTransaction
{
AccountId = accountId,
TransactionId = Guid.NewGuid(),
DateCreated = DateTime.UtcNow,
DateUpdated = DateTime.UtcNow,
TransactionDate = DateTime.UtcNow,
Amount = 2000,
Balance = 13000,
TransactionStatus = 1,
TransactionType = 2
},
new AccountTransaction
{
AccountId = accountId,
TransactionId = Guid.NewGuid(),
DateCreated = DateTime.UtcNow,
DateUpdated = DateTime.UtcNow,
TransactionDate = DateTime.UtcNow,
Amount = 3000,
Balance = 16000,
TransactionStatus = 2,
TransactionType = 1
}
};
await _dbContext.AccountTransactions.AddRangeAsync(accountTransactions);
var result = await _dbContext.SaveChangesAsync();
Console.WriteLine($"{result} data seeded");
}
}
}