Ejemplo n.º 1
0
 public ActionResult Input(Category model)
 {
     try
     {
         //TODO: kiem tra tinh hop le cua du lieu
         if (string.IsNullOrEmpty(model.CategoryName))
         {
             ModelState.AddModelError("CategoryName", "CategoryName expected");
         }
         if (string.IsNullOrEmpty(model.Description))
         {
             model.Description = "";
         }
         if (!ModelState.IsValid)
         {
             ViewBag.Title = model.CategoryID == 0 ? "Create new Category" : "Edit a Category";
             return(View(model));
         }
         //TODO: Luu
         if (model.CategoryID == 0)
         {
             CataLogBLL.AddCategory(model);
         }
         else
         {
             CataLogBLL.UpdateCategory(model);
         }
         return(RedirectToAction("Index"));
     }
     catch (Exception ex)
     {
         ModelState.AddModelError("Loi", ex.StackTrace);
         return(View(model));
     }
 }