public ActionResult CreateCustomer(CustomerModel customerModel)
        {
            var customer = new Customer();
            CustomerFromCustomerModel(customerModel, customer);
            foreach (var addressModel in customerModel.AddressList)
            {
                var a = new Address();
                AddressFromAddressModel(a, addressModel);
                customer.Addresses.Add(a);
            }

            var repository = new CustomerRepository();
            repository.CreateCustomer(customer);
            return RedirectToAction("Customers");
        }
        private CustomerModel CustomerModelFromCustomer(Customer customer)
        {
            var model = new CustomerModel
            {
                CustomerId = customer.CustomerId,
                FirstName = customer.FirstName,
                LastName = customer.LastName,
                MiddleI = customer.MiddleI
            };

            model.AddressList = new List<AddressModel>();

            foreach (var address in customer.Addresses.OrderBy(a=>a.AddressTypeId))
            {
                var addressModel = AddressModelFromAddress(address);
                model.AddressList.Add(addressModel);
            }

            return model;
        }
 private void CustomerFromCustomerModel(CustomerModel customerModel, Customer customer)
 {
     customer.CustomerId = customerModel.CustomerId;
     customer.FirstName = customerModel.FirstName;
     customer.LastName = customerModel.LastName;
     customer.MiddleI = customerModel.MiddleI;
 }