Exemplo n.º 1
0
        public BankModule(ICashDispenser dispenser, IAccountRepository accountRepo)
        {
            _dispenser = dispenser;
            _accountRepo = accountRepo;

            Get["/"] = _ =>
                           {
                               return @"<html>
                                          <body>
                                            <form action='/withdraw' method='post'>
                                              <label for='accountNo'>Account no</label>
                                              <input type='text' name='accountNo' id='accountNo'>
                                              <br />
                                              <label for='amount'>Amount</label>
                                              <input type='text' name='amount' id='amount'>
                                              <br />
                                              <input type='submit' name='withdraw' id='withdraw' value='Withdraw'>
                                            </form>
                                          </body>
                                        </html>";
                           };

            Post["/withdraw"] = p =>
                                    {
                                        var vm = this.Bind<WithdrawalVM>();
                                        var account = _accountRepo.GetAccount(vm.AccountNo);
                                        var teller = new Teller(_dispenser);
                                        teller.AuthenticateAs(account);
                                        teller.Withdraw(vm.Amount);
                                        return "It's done!";
                                    };
        }
Exemplo n.º 2
0
 // Does ALL the work of withdrawing cash - automating that procress
 public static void Whitdraw(int amountToWithdraw)
 {
     var teller = new Teller(CashDispenser);
     teller.AuthenticateAs(MyAccount);
     teller.Withdraw(amountToWithdraw);
 }