Пример #1
0
 /// <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();
             }
         }
     }
 }
Пример #2
0
        internal static Account Deposit(this DestinationAccount toAccount, decimal amount, Action <IAccount> persist)
        {
            var newToAccount = new Account(toAccount.Id, toAccount.Balance + amount);

            persist(newToAccount);
            Console.WriteLine($"Deposited {amount} to Account #{newToAccount.Id}. New Balance = {newToAccount.Balance}.");
            return(newToAccount);
        }