Esempio n. 1
0
 public ActionResult Input(Category model)
 {
     try
     {
         //Kiểm tra tính hợp lệ
         if (string.IsNullOrEmpty(model.CategoryName))
         {
             ModelState.AddModelError("Category_name", "City is required");
         }
         if (string.IsNullOrEmpty(model.Description))
         {
             ModelState.AddModelError("desc", "Fax is required");
         }
         if (!ModelState.IsValid)
         {
             return(View(model));
         }
         if (model.CategoryID == 0)
         {
             int categoryID = CatalogBLL.Category_Add(model);
             return(RedirectToAction("Index"));
         }
         else
         {
             bool updateResult = CatalogBLL.Category_Update(model);
             return(RedirectToAction("Index"));
         }
     }
     catch (Exception e)
     {
         ModelState.AddModelError("", e.Message + ":" + e.StackTrace);
         return(View(model));
     }
 }
        public ActionResult Input(Category model)
        {
            try
            {
                //kiem tra tinh hop le
                if (string.IsNullOrEmpty(model.CategoryName))
                {
                    ModelState.AddModelError("CategoryName", "Category Name is required");
                }
                if (string.IsNullOrEmpty(model.Description))
                {
                    ModelState.AddModelError("Description", "Description is required");
                }
                if (!ModelState.IsValid)
                {
                    return(View(model));
                }

                if (model.CategoryID == 0)
                {
                    int categoryId = CatalogBLL.Category_Add(model);
                    return(RedirectToAction("Index"));
                }
                else
                {
                    bool updateResult = CatalogBLL.Category_Update(model);
                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message + ":" + ex.StackTrace);
                return(View(model));
            }
        }
        public ActionResult Input(Category model)
        {
            try
            {
                if (string.IsNullOrEmpty(model.Description))
                {
                    model.Description = "";
                }

                if (!ModelState.IsValid)
                {
                    if (model.CategoryID == 0)
                    {
                        ViewBag.Title         = "Add New Shipper";
                        ViewBag.ConfirmButton = "Add";
                    }
                    else
                    {
                        ViewBag.Title         = "Edit New Shipper";
                        ViewBag.ConfirmButton = "Save";
                    }
                    return(View(model));
                }
                //Đưa dữ liệu vào CSDL
                if (model.CategoryID == 0)
                {
                    int shipperID = CatalogBLL.Category_Add(model);
                    return(RedirectToAction("Index"));
                }
                else
                {
                    bool rs = CatalogBLL.Category_Update(model);
                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception e)
            {
                return(View(model));
            }
        }
Esempio n. 4
0
        public ActionResult Input(Category data)
        {
            try
            {
                #region Allow Null for Columns

                if (string.IsNullOrEmpty(data.CategoryName))
                {
                    data.CategoryName = "";
                }

                #endregion Allow Null for Columns

                if (string.IsNullOrEmpty(data.CategoryName))
                {
                    ModelState.AddModelError("ErrorCategoryName", "Category Name is required");
                }
                if (!ModelState.IsValid)
                {
                    return(View(data));
                }
                if (data.CategoryID == 0)
                {
                    int categoryId = CatalogBLL.Category_Add(data);
                    return(RedirectToAction("Index"));
                }
                else
                {
                    bool updateResult = CatalogBLL.Category_Update(data);
                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message + ":" + ex.StackTrace);
                return(View(data));
            }
        }
Esempio n. 5
0
        public ActionResult Input(Category model)
        {
            try
            {
                // Check Validate
                if (string.IsNullOrEmpty(model.CategoryName))
                {
                    ModelState.AddModelError("CategoryName", "CategoryName is required");
                }
                if (string.IsNullOrEmpty(model.Description))
                {
                    model.Description = "";
                }

                if (!ModelState.IsValid)
                {
                    ViewBag.Title = model.CategoryID == 0 ? "Add New Category" : "Edit Category";
                    return(View(model));
                }

                // Connect to DB and Insert or Update
                if (model.CategoryID == 0)
                {
                    int categoryID = CatalogBLL.Category_Add(model);
                    return(RedirectToAction("Index"));
                }
                else
                {
                    bool updateCategory = CatalogBLL.Category_Update(model);
                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message + " : " + ex.StackTrace);
                return(View(model));
            }
        }