public ActionResult Save(Customer customer) { if (!ModelState.IsValid) { NewCustomerViewModel viewModel = new NewCustomerViewModel() { Customer = customer, MembershipTypes = _repo.GetMembershipTypes() }; return(View("CustomerForm", viewModel)); } if (customer.Id == 0) { _repo.CreateCustomer(customer); } else { _repo.UpdateCustomer(customer); } return(RedirectToAction("Index", "Customer")); }
public void UpdateCustomer(int id, Customer customer) { if (!ModelState.IsValid) { throw new HttpResponseException(HttpStatusCode.BadRequest); } Customer customerInDb = _repo.GetCustomerById(id); if (customerInDb == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } _repo.UpdateCustomer(customerInDb); }