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; } }
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; }
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; }
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.")); } }
public Config(String pin, Integer ammount, Double rate) : base() { this.Pin = pin; this.Ammount = ammount; this.Rate = rate; }
public Config(String pin, Integer ammount) : base() { this.Pin = pin; this.Ammount = ammount; }
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.")); } }
void DoUnlock() { var transaction = (this.ReceivedEvent as Account.UnlockEvent).Transaction; this.Counter = 0; this.IsLocked = false; this.Send(transaction, new SuccessResponse("Account successfully unlocked!")); }
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; }
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)); }
public OpenedResponse(Integer acctNumber) : base("Account opened.") { this.AccountNumber = acctNumber; }