public ActionResult Input(string id = "") { try { if (string.IsNullOrEmpty(id)) { ViewBag.Title = " Create new Customer"; Customer newCustomer = new Customer() { CustomerID = "" }; return(View(newCustomer)); } else { ViewBag.Title = "Edit a Customer"; Customer editCustomer = CataLogBLL.GetCustomer(id); return(View(editCustomer)); } }catch (Exception ex) { return(Content(ex.Message + "" + ex.StackTrace)); } }
public ActionResult Input(Customer model) { try { if (string.IsNullOrEmpty(model.CustomerID)) { ModelState.AddModelError("CustomerID", "CustomerID expected"); } if (string.IsNullOrEmpty(model.CompanyName)) { ModelState.AddModelError("CompanyName", "CompanyName expected"); } if (string.IsNullOrEmpty(model.ContactName)) { ModelState.AddModelError("ContactName", "ContactName expected"); } if (string.IsNullOrEmpty(model.ContactTitle)) { ModelState.AddModelError("ContactTitle", "ContactTitle expected"); } if (string.IsNullOrEmpty(model.Address)) { model.Address = ""; } if (string.IsNullOrEmpty(model.City)) { model.City = ""; } if (string.IsNullOrEmpty(model.Country)) { model.Country = ""; } if (string.IsNullOrEmpty(model.Fax)) { model.Fax = ""; } if (string.IsNullOrEmpty(model.Phone)) { model.Phone = ""; } if (!ModelState.IsValid) { ViewBag.Title = model.CustomerID == "" ? "Create new Customer" : "Edit a Customer"; return(View(model)); } Customer getCustomer = CataLogBLL.GetCustomer(model.CustomerID); if (getCustomer == null) { // model.CustomerID = method; CataLogBLL.AddCustomer(model); } else { CataLogBLL.UpdateCustomer(model); } return(RedirectToAction("Index")); } catch (Exception ex) { return(Content(ex.Message + "" + ex.StackTrace)); //ModelState.AddModelError("Loi", ex.StackTrace); //return View(model); } }