Update Lesson 4 Task 1
This commit is contained in:
parent
9ad0e7cbb0
commit
49f7d01245
3 changed files with 45 additions and 38 deletions
|
@ -18,42 +18,4 @@
|
|||
Console.WriteLine($"Your balance is: {Balance}");
|
||||
}
|
||||
}
|
||||
|
||||
public class CustomerList
|
||||
{
|
||||
public List<Customer> Customers = new List<Customer>()
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
35
Lesson_4/Task_1/CustomerList.cs
Normal file
35
Lesson_4/Task_1/CustomerList.cs
Normal file
|
@ -0,0 +1,35 @@
|
|||
namespace SingleResponsibility
|
||||
{
|
||||
public class CustomerList
|
||||
{
|
||||
public List<Customer> Customers = new List<Customer>()
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
10
Lesson_4/Task_1/Database.cs
Normal file
10
Lesson_4/Task_1/Database.cs
Normal file
|
@ -0,0 +1,10 @@
|
|||
namespace SingleResponsibility
|
||||
{
|
||||
public class Database
|
||||
{
|
||||
public void SaveToDatabase()
|
||||
{
|
||||
Console.WriteLine("Saved!");
|
||||
}
|
||||
}
|
||||
}
|
Reference in a new issue