Update Lesson 4 Task 1

This commit is contained in:
Stanislav Mykhailenko 2023-04-09 20:44:52 +03:00
parent 9ad0e7cbb0
commit 49f7d01245
GPG key ID: 1E95E66A9C9D6A36
3 changed files with 45 additions and 38 deletions

View file

@ -18,42 +18,4 @@
Console.WriteLine($"Your balance is: {Balance}"); 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();
}
}
}
} }

View 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();
}
}
}
}

View file

@ -0,0 +1,10 @@
namespace SingleResponsibility
{
public class Database
{
public void SaveToDatabase()
{
Console.WriteLine("Saved!");
}
}
}