public virtual void AcceptCashFromParent(Parent parent, decimal amount, string description) { var insufficientFundsMessage = string.Format( "You can not withdraw {0} because {1}'s account only has {2}", amount.ToString("c"), this.Name, this.Account.Balance.ToString("c")); this.WithdrawInternal(parent, amount, description, insufficientFundsMessage); }
public virtual void WithdrawCashFromParent(Parent parent, decimal amount, string description) { var insufficientFundsMessage = string.Format( "You can not withdraw {0} because you only have {1} in your account", amount.ToString("c"), this.Account.Balance.ToString("c")); this.WithdrawInternal(parent, amount, description, insufficientFundsMessage); parent.SendMessage(string.Format("{0} would like to withdraw {1}", this.Name, amount.ToString("c"))); }
public bool AreNullOrNotRelated(Parent parent, Child child) { if (parent == null || child == null) return true; if (!parent.HasChild(child)) { throw new TardisBankException("'{0}' is not a child of '{1}'", child.UserName, parent.UserName); } return false; }
void WithdrawInternal(Parent parent, decimal amount, string description, string insufficientFundsMessage) { if (parent == null) { throw new ArgumentNullException("parent"); } if (description == null) { throw new ArgumentNullException("description"); } if (!parent.HasChild(this)) { throw new CashWithdrawException("Not Your Parent"); } if (amount > this.Account.Balance) { throw new CashWithdrawException(insufficientFundsMessage); } this.Account.AddTransaction(description, -amount); }