This repository has been archived on 2024-10-24. You can view files and clone it, but cannot push or open issues or pull requests.
NG_2023_Stanislav_Mykhailenko/Lesson_4/Task_1/Balance.cs
Stanislav Mykhailenko 20d02a283a
Update Lesson 4 Task 1
2023-04-13 17:54:09 +03:00

32 lines
814 B
C#

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;
}
}
}