public void Execute() //execute the transfer { if (_executed) //if it's allready been executed then throw a error { throw new Exception("Cannot execute as it has already been executed"); } _executed = true; //set executed to true to show that a atempt to transfer happened _theWithdraw.Execute(); if (_theWithdraw._success) //if the withdraw happened successful then deposit the amount in to the to account { _theDeposit.Execute(); if (_theDeposit._success != true) //if the deposit was not successfull then roll back the transcation { Rollback(); } _success = false; //set to false to display it didn't happen } if (_reversed != true) // check to make sure the transfer wasn't reversed { _success = true; // if all went well then set it success to true } }
private static void DoDeposit(Bank toBank) // deposit method { decimal input; //used to store the user inputted amount Account toAccount = FindAccount(toBank); if (toAccount == null) { return; } Utl.lineBreak(); Console.WriteLine("Enter how much you would like to deposit?"); input = Convert.ToDecimal(Console.ReadLine()); //store the amount after converting to decimal var deposit = new DepositTransaction(toAccount, input); //create a new deposit object deposit.Execute(); // excute the deposit on the deposit object deposit.Print(); // and print the object //account.Deposit(input); // call the Deposit method pass the amount to be deposited }