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); }
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); }
internal static void WithdrawFunds(Dictionary <int, Account> accountList, Account account) { if (!account.userLogin) { Console.WriteLine("Please login"); } else { Console.WriteLine("Enter the amount you wish to withdraw: "); string withdrawalinput = Console.ReadLine(); int withdrawal; if (!int.TryParse(withdrawalinput, out withdrawal)) { Console.WriteLine(AccountCreation.errorMessage); } else { int oldBalance = account.Balance; withdrawal = withdrawalValidation(accountList, account, withdrawalinput, withdrawal); TextFileInputOutput.UpdateTextFileBalance(accountList, account, oldBalance); } } }
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; } } }