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 decimal Calculate(Customer customer, Product product)
        {
            if (customer == null)
                throw new ArgumentNullException("customer");

            if (product == null)
                throw new ArgumentNullException("product");

            CountryTax customerCountryTax = this.countryTax.FindOne(new CountryTypeOfTaxSpec(customer.Country.Id, TaxType.Customer));
            CountryTax businessCountryTax = this.countryTax.FindOne(new CountryTypeOfTaxSpec(settings.BusinessCountry.Id, TaxType.Business));

            return (product.Cost * customerCountryTax.Percentage)
                     + (product.Cost * businessCountryTax.Percentage);
        }
        public static Purchase Create(Customer customer, ReadOnlyCollection<CartProduct> cartProducts)
        {
            Purchase purchase = new Purchase()
            {
                Id = Guid.NewGuid(),
                Created = DateTime.Today,
                Customer = customer,
                TotalCost = customer.Cart.TotalCost,
                TotalTax = customer.Cart.TotalTax
            };

            List<PurchasedProduct> purchasedProducts = new List<PurchasedProduct>();
            foreach (CartProduct cartProduct in cartProducts)
            {
                purchasedProducts.Add(PurchasedProduct.Create(purchase, cartProduct));
            }

            purchase.purchasedProducts = purchasedProducts;

            return purchase;
        }
        public static Customer Create(string firstname, string lastname, string email, Country country)
        {
            if (string.IsNullOrEmpty(firstname))
                throw new ArgumentNullException("firstname");

            if (string.IsNullOrEmpty(lastname))
                throw new ArgumentNullException("lastname");

            if (string.IsNullOrEmpty(email))
                throw new ArgumentNullException("email");

            if (country == null)
                throw new ArgumentNullException("country");

            Customer customer = new Customer()
            {
                Id = Guid.NewGuid(),
                FirstName = firstname,
                LastName = lastname,
                Email = email,
                Active = true,
                Created = DateTime.Today,
                Country = country
            };
            customer.Cart = Cart.Create(customer);

            DomainEvents.Raise<CustomerCreated>(new CustomerCreated() { Customer = customer });
            return customer;
        }
 private void validateCustomer(Guid customerId, Customer customer)
 {
     if (customer == null)
         throw new Exception(String.Format("Customer was not found with this Id: {0}", customerId));
 }
 public void Subscribe(Customer customer)
 {
     //call a third party web service here...
 }