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

33 lines
814 B
C#
Raw Permalink Normal View History

2023-04-13 14:54:09 +00:00
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;
}
}
}