public ActionResult Create(CustomerFormViewModel viewModel)
        {
            if (!ViewData.ModelState.IsValid) {
            TempData.SafeAdd(viewModel);
            return this.RedirectToAction(c => c.Create());
              }

              try {
            var customer = new Customer { Code = viewModel.Code, Name = viewModel.Name };
            _customerRepository.SaveOrUpdate(customer);
            TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()] = string.Format("Successfully created customer '{0}'", customer.Name);
              }
              catch (Exception ex) {
            TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()] = string.Format("An error occurred creating the customer: {0}", ex.Message);
            return this.RedirectToAction(c => c.Create());
              }

              return this.RedirectToAction(c => c.Index(null));
        }
        public ActionResult Delete(CustomerFormViewModel viewModel)
        {
            if (!ViewData.ModelState.IsValid) {
            return this.RedirectToAction(c => c.Edit(viewModel.Id));
              }

              try {
            var customer = _customerRepository.Get(viewModel.Id);
            _customerRepository.Delete(customer);
            TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()] = string.Format("Successfully deleted customer '{0}'", customer.Name);
              }
              catch (Exception ex) {
            TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()] = string.Format("An error occurred deleting the customer: {0}", ex.Message);
            return this.RedirectToAction(c => c.Edit(viewModel.Id));
              }

              return this.RedirectToAction(c => c.Index(null));
        }
 public ActionResult Delete(int id)
 {
     var customer = _customerRepository.Get(id);
       var viewModel = new CustomerFormViewModel(customer);
       return View(viewModel);
 }