Exemplo n.º 1
0
 public ActionResult Input(Category model)
 {
     try
     {
         //TODO: kiểm tra tính hợp lệ của dữ liệu được nhập
         if (string.IsNullOrEmpty(model.CategoryName))
         {
             ModelState.AddModelError("CategoryName", "CategoryName expected");
         }
         if (string.IsNullOrEmpty(model.Description))
         {
             ModelState.AddModelError("Description", "Description expected");
         }
         if (!ModelState.IsValid)
         {
             //ViewBag.Title
             return(View(model));
         }
         //TODO: lưu dữ liệu vào DB
         if (model.CategoryID == 0)
         {
             CatalogBLL.AddCategory(model);
         }
         else
         {
             CatalogBLL.UpdateCategory(model);
         }
         return(RedirectToAction("Index"));
     }
     catch (Exception ex)
     {
         ModelState.AddModelError("", ex.Message + ": " + ex.StackTrace);
         return(View(model));
     }
 }
        public ActionResult Input(Category model)
        {
            try
            {
                //TODO:
                if (string.IsNullOrEmpty(model.CategoryName))
                {
                    ModelState.AddModelError("CategoryName", "CategoryName expected");
                }
                if (string.IsNullOrEmpty(model.Description))
                {
                    model.Description = "";
                }

                if (model.CategoryID == 0)
                {
                    CatalogBLL.AddCategory(model);
                }
                else
                {
                    CatalogBLL.UpdateCategory(model);
                }
                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message + ":" + ex.StackTrace);
                return(View(model));
            }
        }
        public IActionResult Input(Category model)
        {
            try
            {
                CheckNotNull(model);
                SetEmptyNullableField(model);

                // Save data into DB
                if (model.CategoryID == 0)
                {
                    CatalogBLL.AddCategory(model);
                }
                else
                {
                    CatalogBLL.UpdateCategory(model);
                }
                return(RedirectToAction("Index"));
            }
            catch (MissingFieldException)
            {
                return(View(model));
            }
            catch (System.Exception ex)
            {
                _logger.LogError(ex.Message + ": " + ex.StackTrace);
                return(View(model));
            }
        }
Exemplo n.º 4
0
        public ActionResult Input(Category model)
        {   // lam that nho them try catch
            // : Kiểm tra tính hợp lệ của dữ liệu được nhập
            if (string.IsNullOrEmpty(model.CategoryName))
            {
                ModelState.AddModelError("CategoryName", "*");
            }

            if (string.IsNullOrEmpty(model.Description))
            {
                model.Description = "";
            }

            if (!ModelState.IsValid)
            {
                if (model.CategoryID == 0)
                {
                    ViewBag.Title = "Create new a Category";
                    SetAlert("Add new Category Fail , Check again!", "warning");
                }

                else
                {
                    ViewBag.Title = "Update a Category";
                    SetAlert("Update Category Fail , Check again!", "warning");
                }
                return(View(model));
            }

            //: Lưu dữ liệu vào DB
            if (model.CategoryID == 0)
            {
                CatalogBLL.AddCategory(model);
                SetAlert("Add new Category success !", "success");
            }
            else
            {
                CatalogBLL.UpdateCategory(model);
                SetAlert("Update Category success !", "success");
            }
            return(RedirectToAction("Index"));
        }
Exemplo n.º 5
0
        public ActionResult Input(Category data)
        {
            //try
            //{
            //TODO: kiểm tr tính hợp lệ của dữ liệu
            if (string.IsNullOrEmpty(data.CategoryName))
            {
                ModelState.AddModelError("CategoryName", "CategoryName Expected");
            }

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

            if (!ModelState.IsValid)
            {
                return(View(data));
            }
            //TODO: Lưu dữ liệu vào DB
            if (data.CategoryID == 0)
            {
                CatalogBLL.AddCategory(data);
            }
            else
            {
                CatalogBLL.UpdateCategory(data);
            }
            return(RedirectToAction("Index"));
            //}
            //catch (Exception ex)
            //{
            //    ModelState.AddModelError("", ex.Message + ": " + ex.StackTrace);
            //    return View(data);
            //}
        }