From 49f7d01245b5151ae1e97add38b3aec010d06e42 Mon Sep 17 00:00:00 2001 From: Stanislav Mykhailenko Date: Sun, 9 Apr 2023 20:44:52 +0300 Subject: [PATCH] Update Lesson 4 Task 1 --- Lesson_4/Task_1/Customer.cs | 38 --------------------------------- Lesson_4/Task_1/CustomerList.cs | 35 ++++++++++++++++++++++++++++++ Lesson_4/Task_1/Database.cs | 10 +++++++++ 3 files changed, 45 insertions(+), 38 deletions(-) create mode 100644 Lesson_4/Task_1/CustomerList.cs create mode 100644 Lesson_4/Task_1/Database.cs diff --git a/Lesson_4/Task_1/Customer.cs b/Lesson_4/Task_1/Customer.cs index 2ff3015..0a2fa34 100644 --- a/Lesson_4/Task_1/Customer.cs +++ b/Lesson_4/Task_1/Customer.cs @@ -18,42 +18,4 @@ Console.WriteLine($"Your balance is: {Balance}"); } } - - public class CustomerList - { - public List Customers = new List() - { - new Customer(1, "Fikus", 0), - new Customer(2, "VHarbar", 100000) - }; - - 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 SaveToDatabase() - { - Console.WriteLine("Saved!"); - } - - public void UpdateBalance(int id, decimal newBalance) - { - var customer = GetById(id); - if (customer != null) - { - customer.Balance = newBalance; - SaveToDatabase(); - } - } - } } diff --git a/Lesson_4/Task_1/CustomerList.cs b/Lesson_4/Task_1/CustomerList.cs new file mode 100644 index 0000000..dcd33de --- /dev/null +++ b/Lesson_4/Task_1/CustomerList.cs @@ -0,0 +1,35 @@ +namespace SingleResponsibility +{ + public class CustomerList + { + public List Customers = new List() + { + new Customer(1, "Fikus", 0), + new Customer(2, "VHarbar", 100000) + }; + + 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; + (new Database()).SaveToDatabase(); + } + } + } +} diff --git a/Lesson_4/Task_1/Database.cs b/Lesson_4/Task_1/Database.cs new file mode 100644 index 0000000..318fc9b --- /dev/null +++ b/Lesson_4/Task_1/Database.cs @@ -0,0 +1,10 @@ +namespace SingleResponsibility +{ + public class Database + { + public void SaveToDatabase() + { + Console.WriteLine("Saved!"); + } + } +}