Пример #1
0
        public void PromptForWithdrawalAmount(Account account)
        {
            do
            {
                Console.Clear();
                Console.WriteLine("Your account has {0:c}.  How much would you like to withdraw?", account.Balance);
                string input = Console.ReadLine();

                decimal withdrawAmt;

                if (decimal.TryParse(input, out withdrawAmt))
                {
                    if (withdrawAmt <= account.Balance)
                    {
                        WithdrawFunds(account, withdrawAmt);
                        return;
                    }
                    else
                    {
                        Console.WriteLine("You have requested to withdraw more than you have available!");
                        Console.ReadLine();
                    }
                }
                else
                {
                    Console.WriteLine("Invalid entry. Press Enter to try again. ");
                    Console.ReadLine();
                }
            } while (true);
        }
Пример #2
0
 private void WithdrawFunds(Account account, decimal withdrawAmt)
 {
     AccountOperations ops = new AccountOperations();
     decimal newBalance = ops.WithdrawFunds(account, withdrawAmt);
     Console.WriteLine("Cha Ching! Your new balance is {0:c}", newBalance);
     Console.ReadLine();
 }
Пример #3
0
        public Response Deposit(Account account, decimal Amount)
        {
            var response = new Response();

            if (Amount > 0)
            {
                account.Balance += Amount;
                var repo = new AccountRepository();
                repo.UpdateAccount(account);

                response.Success = true;
                response.Message = "You have successfully made a deposit.";
                response.DepositInfo = new DepositSlip();
                response.DepositInfo.AccountNumber = account.AccountNumber;
                response.DepositInfo.DepositAmount = Amount;
                response.DepositInfo.NewBalance = account.Balance;

            }
            else
            {
                response.Success = false;
                response.Message = "WTF You have to give a positive amount to deposit!";
            }

            return response;
        }
Пример #4
0
        public Response CreateAccount()
        {
            AccountRepository repo = new AccountRepository();
            Account newAccount = new Account();
            Response response = new Response();

            newAccount.AccountNumber = 1;
            Console.Write("Account holder First name :");
            newAccount.FirstName = Console.ReadLine();
            Console.Write("Account holder Last name :");
            newAccount.LastName = Console.ReadLine();

            newAccount.Balance = 0.00M;

             int returnedAccountNumber = repo.WriteNewLine(newAccount);

            if (returnedAccountNumber == repo.GetAllAccounts().Count)
            {
                response.Success = true;

                response.CreateAccountInfo = new CreateAccountSlip();
                response.CreateAccountInfo.AccountNumber = returnedAccountNumber;
                response.CreateAccountInfo.FirstName = newAccount.FirstName;
                response.CreateAccountInfo.LastName = newAccount.LastName;
                response.CreateAccountInfo.NewBalance = newAccount.Balance;

            }
            else
            {
                response.Success = false;
                response.Message = "The account was not created, please try again.";
            }

            return response;
        }
Пример #5
0
        public void Execute(Account account)
        {
            decimal amount = GetWithdrawalAmount();
            var ops = new AccountOperations();
            var request = new WithDrawalRequest()
            {
                Account = account,
                WithdrawalAmount = amount
            };

            var response = ops.MakeWithDrawal(request);

            if (response.Success)
            {
                Console.Clear();
                Console.WriteLine("Withdrawn from account {0}, New Balance: {1:C}", response.Data.AccountNumber, response.Data.Balance);
                UserInteractions.PressKeyToContinue();
            }
            else
            {
                Console.Clear();
                Console.WriteLine("An Error Occured:  {0}", response.Message);
                UserInteractions.PressKeyToContinue();
            }
        }
Пример #6
0
        public void DeleteAccount(Account accountToDelete)
        {
            List<Account> allAccounts = GetAllAcounts();

            var account = allAccounts.First(a => a.AccountNumber == accountToDelete.AccountNumber);
            allAccounts.Remove(account);

            OverwriteFile(allAccounts);
        }
Пример #7
0
        public void UpdateAccount(Account accountToUpdate)
        {
            var accounts = GetAllAccounts();

            var account = accounts.First(a => a.AccountNumber == accountToUpdate.AccountNumber);
            account.Balance = accountToUpdate.Balance;

            OverwriteFile(accounts);
        }
Пример #8
0
 public void PrintAccountInformation(Account AccountInfo)
 {
     Console.Clear();
     Console.WriteLine("Account Information");
     Console.WriteLine("----------------------------");
     Console.WriteLine("Account Number: {0}",AccountInfo.AccountNumber);
     Console.WriteLine("Name: {0}, {1}", AccountInfo.LastName, AccountInfo.FirstName);
     Console.WriteLine("Account Balance: {0:c}", AccountInfo.Balance);
 }
Пример #9
0
        private Account ConverNumberToAccount(string accountNumber)
        {
            var ops = new AccountOperations();
            var response = ops.GetAccount(accountNumber);
            Console.Clear();

                _currentAccount = response.Data;
                return _currentAccount;
        }
Пример #10
0
        public void UpdateAccount(Account accountToUpdate)
        {
            var allAccounts = GetAllAcounts();

            var existingAccount = allAccounts.First(a => a.AccountNumber == accountToUpdate.AccountNumber);
            existingAccount.Balance = accountToUpdate.Balance;
            existingAccount.FirstName = accountToUpdate.FirstName;
            existingAccount.LastName = accountToUpdate.LastName;

            OverwriteFile(allAccounts);
        }
Пример #11
0
        public void UpdateAccount(Account accountToUpdate1, Account accountToUpdate2)
        {
            var accounts = GetAllAccounts();

            var account1 = accounts.First(a => a.AccountNumber == accountToUpdate1.AccountNumber);
            account1.Balance = accountToUpdate1.Balance;

            var account2 = accounts.First(a => a.AccountNumber == accountToUpdate2.AccountNumber);
            account2.Balance = accountToUpdate2.Balance;

            OverwriteFile(accounts);
        }
Пример #12
0
        public void CreateAccount(Account accountToAdd)
        {
            var allAccounts = GetAllAcounts();

            accountToAdd.AccountNumber = CreateNewAccountNumber();
            accountToAdd.Balance = accountToAdd.Balance;
            accountToAdd.FirstName = accountToAdd.FirstName;
            accountToAdd.LastName = accountToAdd.LastName;

            allAccounts.Add(accountToAdd);

            OverwriteFile(allAccounts);
        }
Пример #13
0
        //Create Account
        public int WriteNewLine(Account account)
        {
            //write a new line a way to calculate new line number
            var accounts = GetAllAccounts();
            int newAccountNumber = accounts.Count+1;//+1 will be the new acct number

            using (var writer = File.AppendText(_filePath))//appends to the end of existing file
            {
                writer.WriteLine("{0},{1},{2},{3}", newAccountNumber, account.FirstName,
                        account.LastName, account.Balance);
            }

            return newAccountNumber;
        }
Пример #14
0
        public void Execute(Account account)
        {
            _currentAccount = account;

            int targetAccountNumber = GetTargetAccountFromUser();
            bool targetAccountExists = DisplayTargetAccountInfo(targetAccountNumber);
            //decimal transferAmount;

            if (targetAccountExists)
            {
                decimal transferAmount = GetTransferAmountFromUser();
                MakeTransfer(transferAmount);
            }
        }
Пример #15
0
        public decimal WithdrawFunds(Account account, decimal withdrawAmt)
        {
            account.Balance -= withdrawAmt;
            using (StreamWriter writer = new StreamWriter(_filePath))
            {
                for (int i = 1; i <= account.AccountNumber; i++)
                {
                    var accounts = File.ReadAllLines(_filePath);
                    accounts[account.AccountNumber]= String.Format("{0},{1},{2},{3}", account.AccountNumber, account.FirstName,account.LastName, account.Balance);
                    File.WriteAllLines(_filePath,accounts);
                    Console.WriteLine("Updating file");

            }
            }
            return account.Balance;
        }
Пример #16
0
        public decimal GetTransferAmount(Account account)
        {
            do
            {
                Console.Write("Enter a transfer amount: ");
                var input = Console.ReadLine();
                decimal amount;
                if (decimal.TryParse(input, out amount))
                {
                    return amount;
                }

                Console.WriteLine("That was not a valid amount.  Please enter in decimal format.");
                UserInteractions.PressKeyToContinue();
                Console.Clear();
            } while (true);
        }
        public void WriteNewAccount()
        {
            Account account = new Account();
            account.FirstName = "Victor";
            account.LastName = "Smith";
            account.Balance = 1000000000000.00M;

            var repo = new AccountRepository();
            var accounts = repo.GetAllAccounts();
            var numAccounts = accounts.Count;

            repo.WriteNewLine(account);

            var accountsAfterAdd = repo.GetAllAccounts();
            var numAccountsAfterAdd = accountsAfterAdd.Count;

            Assert.AreEqual(numAccounts +1, numAccountsAfterAdd);
        }
Пример #18
0
        public void DisplayAccountInformation(int AccountNumber)
        {
            var ops = new AccountOperations();
            var response = ops.GetAccount(AccountNumber);

            if (response.Success)
            {
                _currentAccount = response.AccountInfo;
                PrintAccountInformation(response.AccountInfo);
                DisplayAccountMenu();
            }
            else
            {
                Console.WriteLine("Error Occurred!!!");
                Console.WriteLine(response.Message);
                Console.WriteLine("Move Along...");
                Console.ReadLine();
            }
        }
Пример #19
0
        public List<Account> GetAllAccounts()
        {
            List<Account> accounts = new List<Account>();

            var reader = File.ReadAllLines(_filePath);

            for (int i = 1; i < reader.Length; i++)
            {
                var columns = reader[i].Split(',');
                var account = new Account();
                account.AccountNumber = int.Parse(columns[0]);
                account.FirstName = columns[1];
                account.LastName = columns[2];
                account.Balance = decimal.Parse(columns[3]);

                accounts.Add(account);
            }
            return accounts;
        }
Пример #20
0
        public void Execute(Account account)
        {
            // get transfer amount
            decimal transferAmount = GetTransferAmount(account);
            var ops = new AccountOperations();

            //withdraw transfer amount from that account
            var fromAccountRequest = new WithDrawalRequest()
            {
                Account = account,
                WithdrawalAmount = transferAmount
            };
            var fromAccountResponse = ops.MakeWithDrawal(fromAccountRequest);

            string getTransferAccount = GetTransferAccount();

            //trying to assign the transferTo account as the account in the deposit request.
            //have to change string toAccount to Account
            var getAccountResponse = ops.GetAccount(getTransferAccount);
            var toAccount = getAccountResponse.Data;

            var toAccountRequest = new DepositRequest()
            {
                Account = toAccount,
                DepositAmount = transferAmount
            };

            var toAccountResponse = ops.MakeDeposit(toAccountRequest);

            if (getAccountResponse.Success)
            {
                Console.Clear();
                Console.WriteLine("Transfered from account {0}, New Balance: {1:C}", fromAccountResponse.Data.AccountNumber, toAccountResponse.Data.Balance);
                UserInteractions.PressKeyToContinue();
            }
            else
            {
                Console.Clear();
                Console.WriteLine("An Error Occured:  {0}", fromAccountResponse.Message);
                UserInteractions.PressKeyToContinue();
            }
        }
Пример #21
0
        private void DisplayAccountInformation(string accountNumber)
        {
            var ops = new AccountOperations();
            var response = ops.GetAccount(accountNumber);
            Console.Clear();

            if (response.Success)
            {
                _currentAccount = response.Data;
                PrintAccountDetails(response);
                DisplayActionMenu();
                UserInteractions.PressKeyToContinue();
            }
            else
            {
                Console.WriteLine("A problem occured...");
                Console.WriteLine(response.Message);

                UserInteractions.PressKeyToContinue();
            }
        }
Пример #22
0
        public bool DisplayTargetAccountInfo(int AccountNumber)
        {
            var ops = new AccountOperations();
            var response = ops.GetAccount(AccountNumber);

            if (response.Success)
            {
                _targetAccount = response.AccountInfo;
                Console.WriteLine("We will be transfering money to {0} {1} with Account Number {2} and a current balance of {3}.", _targetAccount.FirstName, _targetAccount.LastName, _targetAccount.AccountNumber, _targetAccount.Balance);
                Console.WriteLine("Press Enter to continue...");
                Console.ReadLine();
                return true;
            }
            else
            {
                Console.WriteLine("Error Occurred!!");
                Console.WriteLine("This account does not exist.");
                Console.WriteLine("Press Enter to continue...");
                Console.ReadLine();
                return false;
            }
        }
Пример #23
0
        public void DisplayAccountInformation(int accountNumber)
        {
            var manager = new AccountManager();

            var response = manager.GetAccount(accountNumber);

            Console.Clear();

            if (response.Success)
            {
                _currentAccount = response.Data;
                PrintAccountDetails(response);
                DisplayLookupMenu();
            }
            else
            {
                Console.WriteLine("A problem occurred...");
                Console.WriteLine(response.Message);
                Console.WriteLine("Press any key to continue...");
                Console.ReadKey();
            }
        }
Пример #24
0
        public void Execute(Account account)
        {
            decimal amount = GetDepositAmount();

            var manager = new AccountManager();

            var response = manager.Deposit(account, amount);

            if (response.Success)
            {
                Console.Clear();
                Console.WriteLine("Deposited {0:c} to account {1}.  New Balance is {2}.", response.Data.DepositAmount, response.Data.AccountNumber, response.Data.NewBalance);
                Console.WriteLine("Press any key to continue...");
                Console.ReadKey();
            }
            else
            {
                Console.Clear();
                Console.WriteLine("An error occurred.  {0}", response.Message);
                Console.WriteLine("Press any key to continue...");
                Console.ReadKey();
            }
        }
Пример #25
0
        public void Execute(Account accountFrom, Account accountTo)
        {
            decimal amount = GetTransferAmount();

            var manager = new AccountManager();

            var response = manager.Transfer(accountFrom, accountTo, amount);

            if (response.Success)
            {
                Console.Clear();
                Console.WriteLine("Transfered {0:c} from account {1} to account {2}. New Balance is {3}.", response.Data.TransferAmount, response.Data.AccountNumberFrom, response.Data.AccountNumberTo, response.Data.NewBalance);
                Console.WriteLine("Press any key to continue...");
                Console.ReadKey();
            }
            else
            {
                Console.Clear();
                Console.WriteLine("An error occurred.  {0)", response.Message);
                Console.WriteLine("Press any key to continue...");
                Console.ReadKey();
            }
        }
Пример #26
0
        public Response Transfer(Account Account1, Account Account2, decimal Amount)
        {
            var response = new Response();

            if (Amount <= Account1.Balance && Amount > 0)
            {
                Account1.Balance -= Amount;
                Account2.Balance += Amount;
                var repo = new AccountRepository();
                repo.UpdateAccount(Account1, Account2);

                response.Success = true;
                response.Message = "You have successfully made a transfer.";
                response.TransferInfo = new TransferSlip();
                response.TransferInfo.CurrentAccountNumber = Account1.AccountNumber;
                response.TransferInfo.CurrentAccountName = Account1.FirstName + " " + Account1.LastName;
                response.TransferInfo.TargetAccountNumber = Account2.AccountNumber;
                response.TransferInfo.TargetAccountName = Account2.FirstName + " " + Account2.LastName;
                response.TransferInfo.TransferAmount = Amount;
                response.TransferInfo.NewBalanceCurrentAccount = Account1.Balance;
                response.TransferInfo.NewBalanceTargetAccount = Account2.Balance;
            }
            else
            {
                response.Success = false;
                if (Amount > Account1.Balance)
                {
                    response.Message = "You cannot transfer more money than you have in your balance!!";
                }
                else
                {
                    response.Message = "That is not a proper transfer amount.";
                }
            }

            return response;
        }
Пример #27
0
        private void GetTransferAccount(int accountNumber)
        {
            var manager = new AccountManager();

            var accountReturned = manager.GetAccount(accountNumber);

            if (accountReturned.Success)
            {
                _toTransferToAccout = accountReturned.Data;
            }
            else
            {
                Console.WriteLine("A problem occurred...");
                Console.WriteLine(accountReturned.Message);
                Console.WriteLine("Press any key to continue...");
                Console.ReadKey();
            }
        }
Пример #28
0
        public void WriteNewLine(Account account)
        {
            var accounts = GetAllAccounts();
            //int newAccountNo = accounts.Count + 1;
            int newAccountNo = accounts.Max(a => a.AccountNumber) + 1;

            using (var writer = File.AppendText(_filePath))
            {
                writer.WriteLine("{0},{1},{2},{3}", newAccountNo, account.FirstName, account.LastName, account.Balance);
            }
        }
Пример #29
0
 public void Execute(Account account)
 {
     _currentAccount = account;
     decimal amount = GetWithdrawalAmountFromUser();
     MakeWithdrawal(amount);
 }
Пример #30
0
 public decimal WithdrawFunds(Account account, decimal withdrawAmt)
 {
     var repo = new AccountRepository();
     decimal newBalance = repo.WithdrawFunds(account, withdrawAmt);
     return newBalance;
 }