public ActionResult Input(string id = "") { if (string.IsNullOrEmpty(id)) { ViewBag.Title = "Add New Customer"; Customer newCustomer = new Customer(); return(View(newCustomer)); } else { try { ViewBag.Title = "Edit Customer"; Customer editCustomer = CatalogBLL.Customer_Get(id); if (editCustomer == null) { return(RedirectToAction("Index")); } return(View(editCustomer)); } catch (FormatException) { return(RedirectToAction("Index")); } } }
public ActionResult Input(string id = "") { if (string.IsNullOrEmpty(id)) { ViewBag.Title = "Add New Customer"; ViewBag.ConfirmButton = "Add"; ViewBag.Method = "add"; Customer newCustomer = new Customer(); newCustomer.CustomerID = ""; return(View(newCustomer)); } else { ViewBag.Title = "Edit Customer"; ViewBag.ConfirmButton = "Save"; ViewBag.Method = "update"; try { Customer editCustomer = CatalogBLL.Customer_Get(id); if (editCustomer == null) { return(RedirectToAction("Index")); } return(View(editCustomer)); } catch (Exception e) { Console.WriteLine(e.Message); return(RedirectToAction("Index")); } } }
public ActionResult Input(Customer model, string method) { try { if (string.IsNullOrEmpty(model.CompanyName)) { ModelState.AddModelError("CompanyName", "Company Name is required"); } if (string.IsNullOrEmpty(model.Phone)) { ModelState.AddModelError("Phone", "Phone is required"); } if (!ModelState.IsValid) { return(View(model)); } Customer customer = CatalogBLL.Customer_Get(model.CustomerID); if (customer == null) { int customerId = CatalogBLL.Customer_Add(model); return(RedirectToAction("Index")); } else { bool updateResult = CatalogBLL.Customer_Update(model); return(RedirectToAction("Index")); } } catch (Exception ex) { ModelState.AddModelError("", ex.Message + ":" + ex.StackTrace); return(View(model)); } }
public ActionResult Detail(string id = "") { if (string.IsNullOrEmpty(id)) { return(RedirectToAction("Index")); } try { Customer model = CatalogBLL.Customer_Get(id); return(View(model)); } catch (Exception e) { return(RedirectToAction("Index")); } }
public ActionResult Input(Customer model, string method) { try { if (String.Equals(method, "Add") == true) { Customer customer = CatalogBLL.Customer_Get(model.CustomerID); if (customer != null) { ModelState.AddModelError("id", "ID customer đã tồn tại"); } if (String.IsNullOrEmpty(model.CompanyName)) { ModelState.AddModelError("CompanyName", "Company Name is required"); } if (String.IsNullOrEmpty(model.Country)) { ModelState.AddModelError("errorAddr", "Vui lòng chọn quốc gia"); } if (!ModelState.IsValid) { ViewBag.method = method; ViewBag.CustomerID = model.CustomerID; return(View(model)); } else { var addCustomer = CatalogBLL.Customer_Add(model); return(RedirectToAction("Index")); } } //if (String.Equals(method, "Edit") == true) else { bool editCustomer = CatalogBLL.Customer_Update(model); return(RedirectToAction("Index")); } } catch (Exception e) { ModelState.AddModelError("", e.Message + ":" + e.StackTrace); return(View(model)); } }
public ActionResult Input(string id = "") { if (string.IsNullOrEmpty(id)) { ViewBag.Title = "Add New Customer"; Customer newCustomer = new Customer(); newCustomer.CustomerID = ""; ViewBag.method = "Add"; return(View(newCustomer)); } else { ViewBag.Title = "Edit Customer"; Customer editCustomer = CatalogBLL.Customer_Get(id); ViewBag.method = "Edit"; if (editCustomer == null) { return(RedirectToAction("index")); } return(View(editCustomer)); } }
public ActionResult Input(Customer model, string method, string tempID) { if (string.IsNullOrEmpty(method)) { return(RedirectToAction("Index")); } else { if (method == "add") { if (!string.IsNullOrEmpty(model.CustomerID)) { if (CatalogBLL.Customer_Get(model.CustomerID) != null) { ModelState.AddModelError("CustomerID", "Customer ID ready exist"); } } } } if (string.IsNullOrEmpty(model.Fax)) { model.Fax = ""; } //Nếu không có trường method thì chuyển hướng về Index if (string.IsNullOrEmpty(method)) { return(RedirectToAction("Index")); } else { if (string.IsNullOrEmpty(model.Fax)) { model.Fax = ""; } //Kiểm tra có tồn tại bất kỳ lỗi nào hay không if (!ModelState.IsValid) { if (method == "add") { ViewBag.Title = "Add New Customer"; ViewBag.ConfirmButton = "Add"; ViewBag.Method = "add"; return(View(model)); } else { ViewBag.Title = "Edit Customer"; ViewBag.ConfirmButton = "Save"; ViewBag.Method = "update"; return(View(model)); } } //Đưa dữ liệu vào CSDL if (method == "add") { int customerID = CatalogBLL.Customer_Add(model); } else if (method == "update") { bool rs = CatalogBLL.Customer_Update(model); } return(RedirectToAction("Index")); } }
public ActionResult ajaxGet(string id = "") { var data = CatalogBLL.Customer_Get(id); return(Json(data)); }