Example #1
0
        private Boolean CheckPin(String p)
        {
            if (!this.IsLocked && p.StringValue().Trim().Equals(this.Pin))
            {
                this.Counter = 0;
                return true;
            }
            else
            {
                this.Counter = this.Counter + 1;

                if (this.Counter >= 3)
                {
                    this.IsLocked = true;
                }

                return false;
            }
        }
Example #2
0
        public Transaction(MachineId machine, Type callback, Integer accountNumber, Integer amount,
            String pin, Integer type, Double rate)
        {
            this.Machine = machine;
            this.Callback = callback;
            this.AccountNumber = accountNumber;
            this.Amount = amount;
            this.Pin = pin;

            if (type == 3)
            {
                this.Type = 3;
                this.Rate = new Double(0.0);
                return;
            }

            if ((type != 0) && (type != 1))
            {
                throw new Exception("Invalid account type.");
            }

            this.Type = type;
            this.Rate = rate;
        }
Example #3
0
 public Transfer(MachineId machine, Type callback, Integer from, Integer to,
     Integer amount, string pin)
     : base(machine, callback, to, amount, pin, 3, 0)
 {
     this.From = from;
 }
Example #4
0
        void DoDeposit()
        {
            var transaction = (this.ReceivedEvent as Account.DepositEvent).Transaction;

            if (this.IsLocked)
            {
                this.Send(transaction, new FailureResponse("Account is locked."));
                return;
            }

            if (!this.CheckPin(transaction.GetPin()))
            {
                this.Send(transaction, new FailureResponse("Invalid PIN."));
                return;
            }

            Double amount = new Double(transaction.GetAmount());

            if (amount < 0)
            {
                this.Send(transaction, new FailureResponse("Deposit failed."));
            }
            else
            {
                this.Cents = this.Cents + (int)amount;
                this.Send(transaction, new SuccessResponse("Deposit succeeded."));
            }
        }
Example #5
0
 public Config(String pin, Integer ammount, Double rate)
     : base()
 {
     this.Pin = pin;
     this.Ammount = ammount;
     this.Rate = rate;
 }
Example #6
0
 public Config(String pin, Integer ammount)
     : base()
 {
     this.Pin = pin;
     this.Ammount = ammount;
 }
Example #7
0
        void DoWithdraw()
        {
            var transaction = (this.ReceivedEvent as Account.WithdrawEvent).Transaction;
            var multiples = (this.ReceivedEvent as Account.WithdrawEvent).Multiples;

            if (this.IsLocked)
            {
                this.Send(transaction, new FailureResponse("Account is locked."));
                return;
            }

            if (!this.CheckPin(transaction.GetPin()))
            {
                this.Send(transaction, new FailureResponse("Invalid PIN."));
                return;
            }

            if (!multiples.BooleanValue() && (transaction.GetAmount() % 2000 != 0))
            {
                this.Send(transaction, new FailureResponse("Withdrawals must be in multiples of 20."));
                return;
            }

            if ((transaction.GetAmount() < 0) || (transaction.GetAmount() > this.Cents))
            {
                this.Send(transaction, new FailureResponse("Withdraw failed."));
            }
            else
            {
                this.Cents = this.Cents - transaction.GetAmount();
                this.Send(transaction, new SuccessResponse("Withdraw succeeded."));
            }
        }
Example #8
0
 void DoUnlock()
 {
     var transaction = (this.ReceivedEvent as Account.UnlockEvent).Transaction;
     this.Counter = 0;
     this.IsLocked = false;
     this.Send(transaction, new SuccessResponse("Account successfully unlocked!"));
 }
Example #9
0
        void DoTransferComplete()
        {
            var response = (this.ReceivedEvent as Account.TransferComplete).Response;

            if (response is SuccessResponse)
            {
                this.Cents = this.Cents + this.TransferTransaction.GetAmount();
                this.Send(this.TransferTransaction, new SuccessResponse("Transfer succeeded!"));
            }
            else
            {
                this.Send(this.TransferTransaction, new FailureResponse("Withdraw during transfer failed."));
            }

            this.TransferTransaction = null;
        }
Example #10
0
        void DoCreateAccount()
        {
            var transaction = (this.ReceivedEvent as CreateAccountEvent).Transaction;

            MachineId newAccount = null;

            Integer accountNumber = this.AccountIds + 1;

            if (transaction.GetAccountType() == 0)
            {
                newAccount = this.CreateMachine(typeof(CheckingAccount), new CheckingAccount.Config(
                    transaction.GetPin(), transaction.GetAmount()));
            }
            else if (transaction.GetAccountType() == 1)
            {
                newAccount = this.CreateMachine(typeof(SavingsAccount), new SavingsAccount.Config(
                    transaction.GetPin(), transaction.GetAmount(), transaction.GetRate()));
            }
            else
            {
                this.Send(transaction, new FailureResponse("Illegal account type."));
                return;
            }

            this.Accounts.Add(accountNumber, newAccount);
            this.AccountIds = this.AccountIds + 1;

            this.Send(transaction, new OpenedResponse(accountNumber));
        }
Example #11
0
 public OpenedResponse(Integer acctNumber)
     : base("Account opened.")
 {
     this.AccountNumber = acctNumber;
 }