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 CustomerFormViewModel(Customer customer) { Id = customer.Id; Code = customer.Code; Name = customer.Name; }