Exemplo n.º 1
0
        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");
        }
Exemplo n.º 2
0
        /// <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
            );
        }
Exemplo n.º 3
0
        public static void Save(Customer customer)
        {
            try
            {
                File.WriteAllLines(LoadPath(), GenerateData(customer));

            }
            catch (Exception e)
            {
                throw new LoadException(e.Message);
            }
        }
Exemplo n.º 4
0
 public static void DepositTo(Customer customer, AccountType type, double amount)
 {
     AccountServices.Credit(amount, customer.Accounts[type]);
 }
Exemplo n.º 5
0
 public static void WidthdrawFrom(Customer customer, AccountType type, double amount)
 {
     AccountServices.Debit(amount, customer.Accounts[type]);
 }
Exemplo n.º 6
0
 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]);
 }
Exemplo n.º 7
0
 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
 }
Exemplo n.º 8
0
 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;
 }
Exemplo n.º 9
0
 /// <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");
 }
Exemplo n.º 10
0
 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;
 }