public static Customer Load() { // If the load file Exists, load the account carefully if (SettingsExist()) try { using (StreamReader file = new StreamReader(LoadPath())) { // Read the file and display it line by line. var line = file.ReadToEnd(); file.Close(); var lines = line.Split(new[] {Environment.NewLine}, StringSplitOptions.None); // Load the customer from the file var customer = new Customer(lines[0]); CustomerServices.SetBalance(customer, AccountType.Checking, double.Parse(lines[1])); CustomerServices.SetBalance(customer, AccountType.Saving, double.Parse(lines[2])); return customer; } } catch (Exception e) { throw new LoadException(e.Message); } throw new LoadException("Something has gone terribley wrong"); }
/// <summary> /// Main Run, setup the customer object, and Create console OptionLists, then run them through the interface manager /// </summary> public void Run() { // Declare the customer _customer = ImportOrCreateCustomer(); // Throw the Customer into a BankerConsoleInterface object, initialize the OptionList localas BankerConsoleInterface( _bankManagerOptions.AccountOptionsList, _bankManagerOptions.OptionsList, _bankManagerOptions.TransactionOptionsList ); }
public static void Save(Customer customer) { try { File.WriteAllLines(LoadPath(), GenerateData(customer)); } catch (Exception e) { throw new LoadException(e.Message); } }
public static void DepositTo(Customer customer, AccountType type, double amount) { AccountServices.Credit(amount, customer.Accounts[type]); }
public static void WidthdrawFrom(Customer customer, AccountType type, double amount) { AccountServices.Debit(amount, customer.Accounts[type]); }
public static void TransferFunds(Customer customer, AccountType to, AccountType @from, double amount) { var accountTo = customer.Accounts[to]; AccountServices.Transfer(amount, ref accountTo, customer.Accounts[from]); }
public static void SetBalance(Customer customer, AccountType to, double amount) { AccountServices.Credit(amount, customer.Accounts[to]); // TODO change this to create a unique Inital Transaction type }
private Customer ImportOrCreateCustomer() { Customer customer; // See if the load file exists, if the directory does not exist, create it // If the file exists.. load it, if not create a new customer and get new from console try { customer = AccountLoader.SettingsExist() ? AccountLoader.Load() : new Customer(_console.ReadANonEmptyString("Customer Name")); } catch (LoadException e) { _console.WriteAErrorLine(e.Message); customer = new Customer(_console.ReadANonEmptyString("Customer Name")); } return customer; }
/// <summary> /// Delete the settings file for the application /// </summary> private void DeleteBankAccountFile() { if (AccountLoader.SettingsExist()) { try { AccountLoader.DeleteFile(); _console.WriteASuccessLine("Settings File Deleted"); _customer = ImportOrCreateCustomer(); } catch (Exception e) { _console.WriteAErrorLine(e.Message); } } else _console.WriteAErrorLine("Settings File Does Not Exist"); }
private static string[] GenerateData(Customer customer) { string[] output = { customer.CustomerName, customer.AccountBalance(AccountType.Checking).ToString(CultureInfo.CurrentCulture), customer.AccountBalance(AccountType.Saving).ToString(CultureInfo.CurrentCulture) }; return output; }