public ActionResult EditCurrentCustomer(int id)
        {
            if (id > 0)
            {
                var customer = _repo.Find(new GetCustomerById(id)).First();

                customer.Company = _repo.Find(new GetCompanyById(customer.Id)).First();
                customer.BillingAddress = _repo.Find(new GetBillingAddressById(customer.Id)).First();

                var model = new CustomerModel()
                {
                    LastName = customer.LastName,
                    CompanyName = customer.Company.Name,
                    Email = customer.Email,
                    FirstName = customer.FirstName,
                    Phone = customer.Phone,
                    Street1 = customer.BillingAddress.Street1,
                    Street2 = customer.BillingAddress.Street2,
                    City = customer.BillingAddress.City,
                    State = customer.BillingAddress.State,
                    Zip = customer.BillingAddress.ZipCode,
                    Id = customer.Id
                };

                return View("EditCustomer", model);
            }

            return RedirectToAction("Index");
        }
        public ActionResult SubmitNewCustomer(CustomerModel model)
        {
            var customer = new Customer
            {
                FirstName = model.FirstName,
                LastName = model.LastName,
                Company = new Company(model.CompanyName),
                Email = model.Email,
                Phone = model.Phone,
                BillingAddress = new CustomerBillingAddress
                {
                    Street1 = model.Street1,
                    Street2 = model.Street2,
                    City = model.City,
                    State = model.State,
                    ZipCode = model.Zip
                }
            };

            if (!ModelState.IsValid) return View("AddCustomer", model);

            _repo.Context.Add(customer);
            _repo.Context.Commit();

            return View("NewCustomerConfirmation", model);
        }
 public ActionResult ViewDetails(Customer customer)
 {
     customer = _repo.Find(new GetCustomerById(customer.Id)).First();
     var model = new CustomerModel()
     {
         LastName = customer.LastName,
         CompanyName = customer.Company.Name,
         Email = customer.Email,
         FirstName = customer.FirstName,
         Phone = customer.Phone,
         Street1 = customer.BillingAddress.Street1,
         Street2 = customer.BillingAddress.Street2,
         City = customer.BillingAddress.City,
         State = customer.BillingAddress.State,
         Zip = customer.BillingAddress.ZipCode,
         Id = customer.Id
     };
     return View("Details", model);
 }
        public ActionResult SubmitEditedCustomer(CustomerModel model)
        {
            var customer = _repo.Find(new GetCustomerById(model.Id)).First();

            customer.Company = _repo.Find(new GetCompanyById(customer.Id)).First();
            customer.BillingAddress = _repo.Find(new GetBillingAddressById(customer.Id)).First();

            customer.FirstName = model.FirstName;
            customer.LastName = model.LastName;
            if (customer.Company.Name != model.CompanyName)
                customer.Company = new Company(model.CompanyName);

            customer.Email = model.Email;
            customer.Phone = model.Phone;

            customer.BillingAddress.Street1 = model.Street1;
            customer.BillingAddress.Street2 = model.Street2;
            customer.BillingAddress.City = model.City;
            customer.BillingAddress.State = model.State;
            customer.BillingAddress.ZipCode = model.Zip;

            if (ModelState.IsValid)
                _repo.Context.Commit();

            return RedirectToAction("Index");
        }