private static int completeTransfer(Dictionary <int, Account> list, Account account, int recipientAccount, string amountInput, int transferAmount) { transferAmount = Convert.ToInt32(amountInput); if (transferAmount <= 0 || transferAmount >= account.Balance) { Console.WriteLine("Amount must be greater than zero and less than your account balance"); } else { int oldBalance = account.Balance; int oldRecipientBalance = list[recipientAccount].Balance; list[account.AccoutNumber].Balance -= transferAmount; Account recipientAccountObject = list[recipientAccount]; recipientAccountObject.Balance = recipientAccountObject.Balance + transferAmount; TextFileInputOutput.UpdateTextFileBalance(list, list[account.AccoutNumber], oldBalance); TextFileInputOutput.UpdateTextFileBalance(list, recipientAccountObject, oldRecipientBalance); formatAmountInCorrectCurrency(list, recipientAccount, transferAmount); Balance.CheckBalance(list, list[account.AccoutNumber]); LoginLogout.Logout(list[account.AccoutNumber], list); } return(transferAmount); }
internal static void CheckBalance(Dictionary <int, Account> list, Account account) { if (!account.userLogin) { Console.WriteLine("Please login"); } else { DateTime currentDateTime = DateTime.Now; TimeSpan timeLoggedIn = currentDateTime - account.LoginTime; Console.WriteLine("Correct as of {0} {1}", currentDateTime.ToLongDateString(), currentDateTime.ToLongTimeString()); Console.WriteLine(AccountCreation.FormatBalanceCurrency(list, account.AccoutNumber)); Console.WriteLine("Total time logged in: {0:0} minutes and {1} seconds", timeLoggedIn.TotalMinutes, timeLoggedIn.Seconds); LoginLogout.Logout(account, list); } }
public static Account CreateNewAccount(Dictionary <int, Account> list) { string message = ""; Account account = new Account(); i = list.Keys.Max() + 1; int accountNumber = i; if (LoginLogout.checkDatabase(list, accountNumber)) { Console.WriteLine("Account already exists"); } else { account.AccoutNumber = accountNumber; account.PIN = PINNumber(); account.userLogin = false; list.Add(account.AccoutNumber, account); account.Currency = CreateCurrency(list, account.AccoutNumber); account.Balance = CreateBalance(list, account.AccoutNumber); string balanceCurrencyOutput = FormatBalanceCurrency(list[accountNumber]); if (checkInput) { TextFileInputOutput.WriteNewAccountToFile(account); message = String.Format("Account successfully created: Account Number: {0}", accountNumber + balanceCurrencyOutput); TextFileInputOutput.ReadAccountsFromFile(list); } else { message = errorMessage; list.Remove(account.AccoutNumber); } Console.WriteLine(message); } i++; Console.ReadLine(); return(account); }
private static int completeDeposit(Dictionary <int, Account> list, int accountnumber, Account account, string depositInput, int depositAmount) { depositAmount = Convert.ToInt32(depositInput); if (depositAmount <= 0) { Console.WriteLine("Input must be greater than 0"); } else { int oldBalance = account.Balance; list[accountnumber].Balance += depositAmount; account.Balance = list[accountnumber].Balance; TextFileInputOutput.UpdateTextFileBalance(list, account, oldBalance); formatAmountInCorrectCurrency(list, accountnumber, depositAmount); LoginLogout.Logout(list[account.AccoutNumber], list); account.userLogin = false; } return(depositAmount); }
private static int withdrawalValidation(Dictionary <int, Account> accountList, Account account, string withdrawalinput, int withdrawal) { withdrawal = Convert.ToInt32(withdrawalinput); if (!checkDivisibility(withdrawal)) { Console.WriteLine("Amount must be a denonimation of 10, 20 or 50"); } else { if (withdrawal <= 0 || withdrawal >= accountList[account.AccoutNumber].Balance) { Console.WriteLine(AccountCreation.errorMessage); } else { accountList[account.AccoutNumber].Balance -= withdrawal; Balance.CheckBalance(accountList, accountList[account.AccoutNumber]); LoginLogout.Logout(accountList[account.AccoutNumber], accountList); account.userLogin = false; } } return(withdrawal); }
static void Main(string[] args) { TextFileInputOutput.CreateStorage(); programStart(); #region variables bool programLoop = true; Account account = new Account(); //INITIAL TEST ACCOUNT CREATION ////false = £GBP //Account testAccount1 = new Account { AccoutNumber = 100000, PIN = 1234, Balance = 10000, Currency = false }; ////true = $USD //Account testAccount2 = new Account { AccoutNumber = 100001, PIN = 1234, Balance = 10000, Currency = true }; //TextFileInputOutput.WriteAccountToFile(testAccount1); //TextFileInputOutput.WriteAccountToFile(testAccount2); //account = testAccount1; //Console.WriteLine("Added two test accounts to the database:"); //Console.WriteLine("Account Number: 100000, PIN: 1234 & Account Number: 100000, PIN: 1234"); Dictionary <int, Account> accountList = new Dictionary <int, Account>(); //accountList.Add(testAccount1.AccoutNumber, testAccount1); //accountList.Add(testAccount2.AccoutNumber, testAccount2); TextFileInputOutput.ReadAccountsFromFile(accountList); Console.ReadLine(); #endregion while (programLoop) { string userInput = initialMessage(); switch (userInput) { case "CREATE": case "C": account.userLogin = false; account = AccountCreation.CreateNewAccount(accountList); break; case "L": LoginLogout.ShortCutAdvice(); break; case "LOGIN": case "LI": account = LoginLogout.Login(account, accountList); break; case "LOGOUT": case "LO": LoginLogout.Logout(account, accountList); break; case "BALANCE": case "B": Balance.CheckBalance(accountList, account); break; case "WITHDRAW": case "W": Withdraw.WithdrawFunds(accountList, account); break; case "DEPOSIT": case "D": Deposit.DepositFunds(accountList, account); break; case "TRANSFER": case "T": Transfer.TransferFunds(accountList, account); break; case "QUIT": case "Q": programLoop = exitProgram(); break; default: Console.WriteLine("Input not understood, please re-enter"); Console.ReadLine(); break; } } }