/// <summary> /// Validate the object. /// </summary> /// <exception cref="ValidationException"> /// Thrown if validation fails /// </exception> public virtual void Validate() { if (SourceAccount == null) { throw new ValidationException(ValidationRules.CannotBeNull, "SourceAccount"); } if (DestinationAccount == null) { throw new ValidationException(ValidationRules.CannotBeNull, "DestinationAccount"); } if (Contents == null) { throw new ValidationException(ValidationRules.CannotBeNull, "Contents"); } if (SourceAccount != null) { SourceAccount.Validate(); } if (DestinationAccount != null) { DestinationAccount.Validate(); } if (Contents != null) { foreach (var element in Contents) { if (element != null) { element.Validate(); } } } }
public void Transference() { if (SourceAccount.Balance < Amount) { AddNotification(new Notification("", "Saldo insuficiente")); return; } SourceAccount.Debit(Amount); TargetAccount.Credit(Amount); }
internal static Account Withdraw(this SourceAccount fromAccount, decimal amount, Action <IAccount> persist) { if (fromAccount.Balance < amount) { throw new Exception("Insufficient funds"); } var newFromAccount = new Account(fromAccount.Id, fromAccount.Balance - amount); persist(newFromAccount); Console.WriteLine($"Withrew {amount} from Account #{newFromAccount.Id}. New Balance = {newFromAccount.Balance}."); return(newFromAccount); }