From 20d02a283a5da062726555cb8c8de17a6bf12693 Mon Sep 17 00:00:00 2001 From: Stanislav Mykhailenko Date: Thu, 13 Apr 2023 17:54:09 +0300 Subject: [PATCH] Update Lesson 4 Task 1 --- Lesson_4/Task_1/Balance.cs | 32 ++++++++++++++++++++++++++++++++ Lesson_4/Task_1/CustomerList.cs | 21 --------------------- 2 files changed, 32 insertions(+), 21 deletions(-) create mode 100644 Lesson_4/Task_1/Balance.cs diff --git a/Lesson_4/Task_1/Balance.cs b/Lesson_4/Task_1/Balance.cs new file mode 100644 index 0000000..e233ac3 --- /dev/null +++ b/Lesson_4/Task_1/Balance.cs @@ -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; + } + } +} diff --git a/Lesson_4/Task_1/CustomerList.cs b/Lesson_4/Task_1/CustomerList.cs index 005ec3e..788c654 100644 --- a/Lesson_4/Task_1/CustomerList.cs +++ b/Lesson_4/Task_1/CustomerList.cs @@ -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; - } } }