Skip to content

Commit 25dc8c4

Browse files
committed
updated LP4 M2 solution
1 parent 5909fec commit 25dc8c4

25 files changed

Lines changed: 2599 additions & 937 deletions

DownloadableCodeProjects/LP4_manage-app-data/Data_M2/Solution/Data_M1.csproj renamed to DownloadableCodeProjects/LP4_manage-app-data/Data_M2/Solution/Data_M2.csproj

File renamed without changes.
Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1-
namespace Data_M1;
1+
namespace Data_M2;
22

33
public interface IBankAccount
44
{
55
int AccountNumber { get; }
66
string CustomerId { get; }
77
double Balance { get; }
88
string AccountType { get; }
9+
BankCustomer Owner { get; } // This is the BankCustomer object that owns the account
910

10-
void Deposit(double amount);
11-
bool Withdraw(double amount);
12-
bool Transfer(IBankAccount targetAccount, double amount);
13-
void ApplyInterest(double years);
14-
void ApplyRefund(double refund);
15-
bool IssueCashiersCheck(double amount);
11+
void Deposit(double amount, DateOnly transactionDate, TimeOnly transactionTime, string description);
12+
bool Withdraw(double amount, DateOnly transactionDate, TimeOnly transactionTime, string description);
13+
bool Transfer(IBankAccount targetAccount, double amount, DateOnly transactionDate, TimeOnly transactionTime, string description);
14+
void ApplyInterest(double years, DateOnly transactionDate, TimeOnly transactionTime, string description);
15+
void ApplyRefund(double refund, DateOnly transactionDate, TimeOnly transactionTime, string description);
16+
bool IssueCashiersCheck(double amount, DateOnly transactionDate, TimeOnly transactionTime, string description);
1617
string DisplayAccountInfo();
18+
void AddTransaction(Transaction transaction);
19+
List<Transaction> GetAllTransactions();
1720
}
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
1-
namespace Data_M1;
1+
namespace Data_M2;
22

33
public interface IBankCustomer
44
{
55
string FirstName { get; set; }
66
string LastName { get; set; }
77
string CustomerId { get; }
8+
IReadOnlyList<IBankAccount> Accounts { get; }
89

910
string ReturnFullName();
1011
void UpdateName(string firstName, string lastName);
1112
string DisplayCustomerInfo();
1213
bool IsPremiumCustomer();
1314
void ApplyBenefits();
14-
}
15+
void AddAccount(IBankAccount account);
16+
void RemoveAccount(IBankAccount account);
17+
IEnumerable<IBankAccount> GetAllAccounts();
18+
IEnumerable<IBankAccount> GetAccountsByType(string accountType);
19+
}
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
using System;
22

3-
namespace Data_M1;
3+
namespace Data_M2;
44

55
public interface IMonthlyReportGenerator
66
{
7-
void GenerateMonthlyReport(Transaction[] transactions, DateOnly reportDate);
8-
void GenerateCurrentMonthToDateReport(Transaction[] transactions, DateOnly reportDate);
9-
void GeneratePrevious30DayReport(Transaction[] transactions, DateOnly reportDate);
7+
void GenerateMonthlyReport(BankCustomer bankCustomer, int accountNumber, DateOnly reportDate);
8+
void GenerateCurrentMonthToDateReport(BankCustomer bankCustomer, int accountNumber, DateOnly reportDate);
9+
void GeneratePrevious30DayReport(BankCustomer bankCustomer, int accountNumber, DateOnly reportDate);
10+
1011
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
using System;
22

3-
namespace Data_M1;
3+
namespace Data_M2;
44

55
public interface IQuarterlyReportGenerator
66
{
7-
void GenerateQuarterlyReport(Transaction[] transactions, DateOnly reportDate);
7+
void GenerateQuarterlyReport(BankCustomer bankCustomer, int accountNumber, DateOnly reportDate);
88
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
using System;
22

3-
namespace Data_M1;
3+
namespace Data_M2;
44

55
public interface IYearlyReportGenerator
66
{
7-
void GeneratePreviousYearReport(Transaction[] transactions, DateOnly reportDate);
8-
void GenerateCurrentYearToDateReport(Transaction[] transactions, DateOnly reportDate);
9-
void GenerateLast365DaysReport(Transaction[] transactions, DateOnly reportDate);
7+
void GeneratePreviousYearReport(BankCustomer bankCustomer, int accountNumber, DateOnly reportDate);
8+
void GenerateCurrentYearToDateReport(BankCustomer bankCustomer, int accountNumber, DateOnly reportDate);
9+
void GenerateLast365DaysReport(BankCustomer bankCustomer, int accountNumber, DateOnly reportDate);
1010
}
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
namespace Data_M2;
5+
6+
public class Bank
7+
{
8+
// Fields
9+
private readonly Guid _bankId;
10+
private readonly List<BankCustomer> _customers;
11+
12+
// Properties
13+
public Guid BankId => _bankId;
14+
public IReadOnlyList<BankCustomer> Customers => _customers.AsReadOnly();
15+
16+
// Constructors
17+
public Bank()
18+
{
19+
_bankId = Guid.NewGuid();
20+
_customers = new List<BankCustomer>();
21+
}
22+
23+
// Methods
24+
internal IEnumerable<BankCustomer> GetAllCustomers()
25+
{
26+
return new List<BankCustomer>(_customers);
27+
}
28+
29+
internal IEnumerable<BankCustomer> GetCustomersByName(string firstName, string lastName)
30+
{
31+
List<BankCustomer> matchingCustomers = new List<BankCustomer>();
32+
foreach (var customer in _customers)
33+
{
34+
if (customer.FirstName.Equals(firstName, StringComparison.OrdinalIgnoreCase) &&
35+
customer.LastName.Equals(lastName, StringComparison.OrdinalIgnoreCase))
36+
{
37+
matchingCustomers.Add(customer);
38+
}
39+
}
40+
return matchingCustomers;
41+
}
42+
43+
// get customer based on Customer ID
44+
internal BankCustomer GetCustomerById(string customerId)
45+
{
46+
foreach (var customer in _customers)
47+
{
48+
if (customer.CustomerId.Equals(customerId, StringComparison.OrdinalIgnoreCase))
49+
{
50+
return customer;
51+
}
52+
}
53+
return null;
54+
}
55+
56+
internal int GetNumberOfTransactions()
57+
{
58+
int totalTransactions = 0;
59+
foreach (BankCustomer customer in _customers)
60+
{
61+
foreach (BankAccount account in customer.Accounts)
62+
{
63+
foreach (Transaction transaction in account.Transactions)
64+
{
65+
totalTransactions++;
66+
}
67+
}
68+
}
69+
return totalTransactions;
70+
}
71+
72+
internal double GetTotalMoneyInVault()
73+
{
74+
double totalBankCash = 0;
75+
foreach (BankCustomer customer in _customers)
76+
{
77+
foreach (BankAccount account in customer.Accounts)
78+
{
79+
totalBankCash += account.Balance;
80+
}
81+
}
82+
return totalBankCash;
83+
}
84+
85+
internal double GetDailyDeposits(DateOnly date)
86+
{
87+
double totalDailyDeposits = 0;
88+
foreach (BankCustomer customer in _customers)
89+
{
90+
foreach (BankAccount account in customer.Accounts)
91+
{
92+
foreach (Transaction transaction in account.Transactions)
93+
{
94+
if (transaction.TransactionDate == date && transaction.TransactionType == "Deposit")
95+
{
96+
totalDailyDeposits += transaction.TransactionAmount;
97+
}
98+
}
99+
}
100+
}
101+
return totalDailyDeposits;
102+
}
103+
104+
internal double GetDailyWithdrawals(DateOnly date)
105+
{
106+
double totalDailyWithdrawals = 0;
107+
foreach (BankCustomer customer in _customers)
108+
{
109+
foreach (BankAccount account in customer.Accounts)
110+
{
111+
foreach (Transaction transaction in account.Transactions)
112+
{
113+
if (transaction.TransactionDate == date && transaction.TransactionType == "Withdraw")
114+
{
115+
totalDailyWithdrawals += transaction.TransactionAmount;
116+
}
117+
}
118+
}
119+
}
120+
return totalDailyWithdrawals;
121+
}
122+
123+
internal void AddCustomer(BankCustomer customer)
124+
{
125+
_customers.Add(customer);
126+
}
127+
128+
internal void RemoveCustomer(BankCustomer customer)
129+
{
130+
_customers.Remove(customer);
131+
}
132+
}

0 commit comments

Comments
 (0)