-
Notifications
You must be signed in to change notification settings - Fork 0
/
Transactions.cs
66 lines (51 loc) · 1.91 KB
/
Transactions.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
using Banking_App_Console.Helpers;
using ConsoleTables;
namespace Banking_App_Console
{
internal class Transactions
{
public Transactions(Dashboard dashboard)
{
var user = Session.Instance.User;
Console.WriteLine();
var table = new ConsoleTable("Reference", "Amount", "Date");
var userTransRows = FileSystem.FindAllTransactions(user.Id);
foreach (var rowData in userTransRows)
{
var transAmount = rowData.Amount;
var transferredByCrUser = false;
if (rowData.From == user.Id)
{
transAmount = "-" + transAmount;
transferredByCrUser = true;
}
string? reference;
if (rowData.From == "none")
reference = "Money Deposited";
else if (rowData.To == "none")
reference = "Money Withdrew";
else
{
string? otherUserCond;
// if the transaction is done by current logged-In user to some other user
if (transferredByCrUser)
{
otherUserCond = rowData.To;
reference = "Money Transferred to: ";
}
else
{
otherUserCond = rowData.From;
reference = "Money Deposited by: ";
}
var userTransdata = FileSystem.FindAUser(otherUserCond);
reference += userTransdata.Email + " - " + userTransdata.Cnic;
}
table.AddRow(reference, transAmount, rowData.Date);
}
Console.Clear(); Console.WriteLine("\x1b[3J");
table.Write();
dashboard.Init();
}
}
}