public IActionResult Input(Supplier supplier) { try { CheckNotNull(supplier); SetEmptyNullableField(supplier); // Save data into DB if (supplier.SupplierId == 0) { CatalogBLL.AddSupplier(supplier); } else { CatalogBLL.UpdateSupplier(supplier); } return(RedirectToAction("Index")); } catch (MissingFieldException) { return(View(supplier)); } catch (Exception ex) { _logger.LogError(ex.Message + ": " + ex.StackTrace); return(View(supplier)); } }
public ActionResult Input(Supplier model) { try { //TODO :Kiểm tra tính hợp lệ của dữ liệu nhập vào 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.Country)) { model.Country = ""; } if (string.IsNullOrEmpty(model.City)) { model.City = ""; } if (string.IsNullOrEmpty(model.Phone)) { model.Phone = ""; } if (string.IsNullOrEmpty(model.Fax)) { model.Fax = ""; } if (string.IsNullOrEmpty(model.HomePage)) { model.HomePage = ""; } //TODO :Lưu dữ liệu nhập vào if (model.SupplierID == 0) { CatalogBLL.AddSupplier(model); } else { CatalogBLL.UpdateSupplier(model); } return(RedirectToAction("Index")); } catch (Exception ex) { ModelState.AddModelError("", ex.Message + ":" + ex.StackTrace); return(View(model)); } }
public ActionResult Input(Supplier model) { //TODO: Kiểm tra tính hợp lệ của dữ liệu được nhập 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.Country)) model.Country = ""; if (string.IsNullOrEmpty(model.City)) model.City = ""; if (string.IsNullOrEmpty(model.Address)) model.Address = ""; if (string.IsNullOrEmpty(model.Phone)) model.Phone = ""; if (string.IsNullOrEmpty(model.Fax)) model.Fax = ""; if (string.IsNullOrEmpty(model.HomePage)) model.HomePage = ""; if (!ModelState.IsValid) { ViewBag.Title = model.SupplierID == 0 ? "Create new Supplier" : "Edit Supplier"; return View(model); } //TODO: Lưu dữ liệu vao DB if (model.SupplierID == 0) { CatalogBLL.AddSupplier(model); } else { CatalogBLL.UpdateSupplier(model); } return RedirectToAction("Index"); }
public ActionResult Input(Supplier data) { //try //{ //TODO: kiểm tr tính hợp lệ của dữ liệu if (string.IsNullOrEmpty(data.CompanyName)) { ModelState.AddModelError("CompanyName", "CompanyName Expected"); } if (string.IsNullOrEmpty(data.ContactName)) { ModelState.AddModelError("ContactName", "ContactName Expected"); } if (string.IsNullOrEmpty(data.ContactTitle)) { ModelState.AddModelError("ContactTitle", "ContactTitle Expected"); } if (string.IsNullOrEmpty(data.Address)) { data.Address = ""; } if (string.IsNullOrEmpty(data.Country)) { data.Country = ""; } if (string.IsNullOrEmpty(data.City)) { data.City = ""; } if (string.IsNullOrEmpty(data.Phone)) { data.Phone = ""; } if (string.IsNullOrEmpty(data.Fax)) { data.Fax = ""; } if (string.IsNullOrEmpty(data.HomePage)) { data.HomePage = ""; } if (!ModelState.IsValid) { return(View(data)); } //TODO: Lưu dữ liệu vào DB if (data.SupplierID == 0) { CatalogBLL.AddSupplier(data); } else { CatalogBLL.UpdateSupplier(data); } return(RedirectToAction("Index")); //} //catch (Exception ex) //{ // ModelState.AddModelError("", ex.Message + ": " + ex.StackTrace); // return View(data); //} }
public ActionResult Input(Supplier model) { // lam that nho them try cacht // : Kiểm tra tính hợp lệ của dữ liệu được nhập if (string.IsNullOrEmpty(model.CompanyName)) { ModelState.AddModelError("CompanyName", "CompanyName expected"); } if (string.IsNullOrEmpty(model.ContactTitle)) { ModelState.AddModelError("ContactTitle", "ContactTitle expected"); } if (string.IsNullOrEmpty(model.ContactName)) { ModelState.AddModelError("ContactName", "ContactName 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.Phone)) { model.Phone = ""; } if (string.IsNullOrEmpty(model.Fax)) { model.Fax = ""; } if (string.IsNullOrEmpty(model.HomePage)) { model.HomePage = ""; } if (!ModelState.IsValid) { ViewBag.Title = "Create new a Supplier "; SetAlert("Add new Supplier Fail , Check again!", "danger"); return(View(model)); } // : Lưu dữ liệu vào DB if (model.SupplierID == 0) { SetAlert("Add new Supplier success !", "success"); CatalogBLL.AddSupplier(model); } else { SetAlert("Update Supplier success !", "success"); CatalogBLL.UpdateSupplier(model); } return(RedirectToAction("Index")); }