public static CreditCard Create(Customer customer, string name, long cardNum, DateTime expiry) { if (customer == null) throw new Exception("Customer object can't be null"); if (string.IsNullOrEmpty(name)) throw new Exception("Name can't be empty"); if (cardNum < 6) throw new Exception("Card number length is incorrect"); if (DateTime.Now > expiry) throw new Exception("Credit card expiry can't be in the past"); CreditCard creditCard = new CreditCard { Customer = customer, NameOnCard = name, CardNumber = cardNum, Expiry = expiry, Active = true, Created = DateTime.Today }; if(customer.CreditCards.Contains(creditCard)) throw new Exception("Can't add same card to the collection"); return creditCard; }
public virtual void Add(CreditCard creditCard) { this.creditCards.Add(creditCard); }