public ActionResult Input(Customer model, int kt) { try { //TODO :Kiểm tra tính hợp lệ của dữ liệu nhập vào 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.Country)) { model.Country = ""; } if (string.IsNullOrEmpty(model.City)) { model.City = ""; } if (string.IsNullOrEmpty(model.Phone)) { model.Phone = ""; } if (string.IsNullOrEmpty(model.Fax)) { model.Fax = ""; } //TODO :Lưu dữ liệu nhập vào if (Convert.ToInt32(kt) == 0) { ViewBag.kt = 0; CatalogBLL.AddCustomerr(model); } else if (Convert.ToInt32(kt) == 1) { ViewBag.kt = 1; CatalogBLL.UpdateCustomer(model); } return(RedirectToAction("Index")); } catch (Exception ex) { ModelState.AddModelError("", ex.Message + ":" + ex.StackTrace); return(View(model)); } }