public void Deposit(Amount amount, DateTime dateTime) { if (amount.isNegative()) { throw new Exception("Impossible to make the deposit : negative amount"); } if (amount.isPositive()) { _balance.IncreaseAmount(amount); Operation deposit = new Deposit(amount, dateTime); _operations.AddOperation(deposit); } }
static void Main(string[] args) { try { DisplayMenu(); var input = Console.ReadLine(); Account account = null; DateTime date = DateTime.Now; while (input.ToString().ToUpper() != "Z") { if (input.ToString() == "1") { if (account != null) { Console.WriteLine("Account already exists"); DisplayMenu(); } else { Console.WriteLine("Enter the amount to create account"); Amount amount = ConvertResponseInAmount(); if (amount.Value > -1) { account = new Account(amount, date); if (amount.isPositive()) { Console.WriteLine($"Creation of account with an initial deposit of {amount} done"); } else { Console.WriteLine($"Creation of account done"); } } DisplayMenu(); } } else if (input.ToString() == "2") { if (CheckIfAccountExistsAndAdvertClient(account)) { Console.WriteLine("Enter the amount of the deposit"); Amount amount = ConvertResponseInAmount(); if (amount.isPositive()) { account.Deposit(amount, date); Console.WriteLine($"Deposit of {amount} done"); } DisplayMenu(); } } else if (input.ToString() == "3") { if (CheckIfAccountExistsAndAdvertClient(account)) { Console.WriteLine("Enter the amount of the withdrawal"); Amount amount = ConvertResponseInAmount(); if (amount.isPositive()) { account.Withdrawal(amount, date); Console.WriteLine($"Withdrawal of {amount} done"); } DisplayMenu(); } } else if (input.ToString() == "4") { if (CheckIfAccountExistsAndAdvertClient(account)) { List <string> records = account.GetOperationsHistoryList(); Console.WriteLine(string.Join(Environment.NewLine, records)); DisplayMenu(); } } else { Console.WriteLine("Instruction not found"); DisplayMenu(); } input = Console.ReadLine(); } } catch (Exception ex) { Console.WriteLine($"Error : {ex.Message}"); Console.ReadKey(); } }