public ActionResult Create(CustomerDto customerDto) { try { customerDto.Validate(ModelState); if (ModelState.IsValid) { service.SaveCustomer(customerDto); return RedirectToAction("Index"); } return View(customerDto); } catch (Exception e) { ModelState.AddModelError("", e.Message); return View(customerDto); } }
public ActionResult Edit(string id, CustomerDto customerDto) { try { if (id != customerDto.CustomerID) { throw new InvalidOperationException(); } customerDto.Validate(ModelState); if (ModelState.IsValid) { service.UpdateCustomer(customerDto); return RedirectToAction("Index"); } return View(customerDto); } catch (Exception e) { ModelState.AddModelError("", e.Message); return View(customerDto); } }