//Gets the Edit View
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            //Query to Load the CustomerLocation
            var customerLocation = new GetCustomerLocationQuery(Context)
                                   .Execute(id: (int)id, includeCustomer: true);

            if (customerLocation == null)
            {
                return(HttpNotFound());
            }

            //Set the CustomerLocation and Customer Properties of the CustomerLocationBaseViewModel
            //so that the needed Customer CustomerLocation properties will be displayed in the View.
            var viewModel = new CustomerLocationEditViewModel()
            {
                CustomerLocation = customerLocation,
                Customer         = customerLocation.Customer
            };

            return(View(viewModel));
        }
        public ActionResult Edit(CustomerLocationEditViewModel viewModel)
        {
            var customerLocation = viewModel.CustomerLocation;

            //Server side Validation to ensure that the Address of the CustomerLocation is updated.
            CustomerLocationValidator(customerLocation);

            if (ModelState.IsValid)
            {
                Context.Entry(customerLocation).State = EntityState.Modified;
                Context.SaveChanges();

                TempData["Message"] = "The address update was successful!";
                return(RedirectToAction("Detail", "Customer", new { id = viewModel.CustomerId }));
            }

            //Reload the Customer to Display the name in the h2 of the Edit View if there is a ModelState Error
            // from not updating the address of the CustomerLocation.
            viewModel.Customer = new GetCustomerQuery(Context)
                                 .Execute((int)viewModel.CustomerId, false);
            return(View(viewModel));
        }