Update Lesson 4 Task 1
This commit is contained in:
parent
d1cee955df
commit
20d02a283a
2 changed files with 32 additions and 21 deletions
32
Lesson_4/Task_1/Balance.cs
Normal file
32
Lesson_4/Task_1/Balance.cs
Normal file
|
@ -0,0 +1,32 @@
|
|||
namespace SingleResponsibility
|
||||
{
|
||||
public class Balance
|
||||
{
|
||||
private readonly CustomerList _customerList;
|
||||
|
||||
public Balance(CustomerList customerList)
|
||||
{
|
||||
_customerList = customerList;
|
||||
}
|
||||
|
||||
public void GetBalance(int id)
|
||||
{
|
||||
Console.WriteLine($"Your balance is: {GetBalanceById(id)}");
|
||||
}
|
||||
|
||||
public decimal? GetBalanceById(int id)
|
||||
{
|
||||
var customer = _customerList.GetById(id);
|
||||
if (customer != null)
|
||||
return customer.Balance;
|
||||
return null;
|
||||
}
|
||||
|
||||
public void UpdateBalance(int id, decimal newBalance)
|
||||
{
|
||||
var customer = _customerList.GetById(id);
|
||||
if (customer != null)
|
||||
customer.Balance = newBalance;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -8,30 +8,9 @@
|
|||
new Customer(2, "VHarbar", 100000)
|
||||
};
|
||||
|
||||
public void GetBalance(int id)
|
||||
{
|
||||
Console.WriteLine($"Your balance is: {GetBalanceById(id)}");
|
||||
}
|
||||
|
||||
public decimal? GetBalanceById(int id)
|
||||
{
|
||||
var customer = Customers.FirstOrDefault(x => x.Id == id);
|
||||
if (customer != null)
|
||||
return customer.Balance;
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
public Customer? GetById(int id)
|
||||
{
|
||||
return Customers.FirstOrDefault(x => x.Id == id);
|
||||
}
|
||||
|
||||
public void UpdateBalance(int id, decimal newBalance)
|
||||
{
|
||||
var customer = GetById(id);
|
||||
if (customer != null)
|
||||
customer.Balance = newBalance;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue