Exemplo n.º 1
0
        public ActionResult <Account> DepositIntoAccount(int accountId, [FromBody] Transactions transaction)
        {
            var depositCreated = _bankService.DepositIntoAccount(accountId, transaction);

            if (depositCreated == null)
            {
                return(BadRequest());
            }
            return(depositCreated);
        }
Exemplo n.º 2
0
        public void TestDepositIntoAccount()
        {
            IBankService bankService = ServiceProvider.GetService <IBankService>();

            Account account = CreateTestAccount("username", "password");

            bankService.CreateAccount(account);
            Transactions transactions    = CreateTestDepositTransaction(account, 100);
            double       expectedBalance = account.Balance + transactions.TransactionAmount;

            bankService.DepositIntoAccount(account.AccountId, transactions);

            Assert.Equal(account.Balance, expectedBalance);
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            // Start up and create defaults.
            IBankService bankService = StartUp.GetConfiguredServices();

            StartUp.CreatePreconfiguredAccounts(bankService);
            string username;
            string password;

            // Welcome message.
            DisplayMessaging.WelcomeMessage();
            string createOrNot = Console.ReadLine().ToLower();

            if (createOrNot.Equals("create"))
            {
                Account newAccount = null;
                while (newAccount == null)
                {
                    newAccount = DisplayMessaging.CreateNewAccountFromUser(bankService);
                }
            }

            // User selection and interactions.
            Selections convertedInput;

            while (true)
            {
                // User must log into an account first.
                Console.WriteLine("Please log into an account");
                Console.WriteLine("Enter username: "******"Enter password: "******"Amount to withdraw from account: ");
                        input = Console.ReadLine();
                        while (!Int32.TryParse(input, out intValue))
                        {
                            Console.WriteLine("Not a valid number to deposit");
                            Console.WriteLine("Amount to withdraw from account: ");
                            input = Console.ReadLine();
                        }
                        Transactions transactionWithdraw = HelperFunctions.CreateTransaction((int)userKey, intValue, "Withdraw");
                        bankService.WithdrawlFromAccount((int)userKey, transactionWithdraw);
                        break;

                    case Selections.DepositIntoAccount:
                        Console.WriteLine("Amount to deposit into account: ");
                        input = Console.ReadLine();
                        while (!Int32.TryParse(input, out intValue))
                        {
                            Console.WriteLine("Not a valid number to deposit");
                            Console.WriteLine("Amount to deposit into account: ");
                            input = Console.ReadLine();
                        }
                        Transactions transactionDeposit = HelperFunctions.CreateTransaction((int)userKey, intValue, "Deposit");
                        bankService.DepositIntoAccount((int)userKey, transactionDeposit);
                        break;

                    case Selections.SeeTransactionHistory:
                        IEnumerable <Transactions> transactionHistory = bankService.GetAllTransactionsForAccount((int)userKey);
                        DisplayMessaging.PrettyDisplayTransactions(transactionHistory);
                        break;

                    case Selections.CreateAccount:
                        Account accountToCreate = DisplayMessaging.CreateNewAccountFromUser(bankService);
                        Account createdAccount  = bankService.CreateAccount(accountToCreate);
                        break;

                    case Selections.LogOut:
                        if (bankService.Logout())
                        {
                            userKey = 0;
                            account = null;
                        }
                        break;

                    default:
                        DisplayMessaging.InvalidInput();
                        break;
                    }
                }
            }
        }