Exemplo n.º 1
0
        public ActionResult OnCreate(NewsCategoryModels category)
        {
            if (ModelState.IsValid)
            {
                var result = NewsGroupService.Insert
                             (
                    category.Name,
                    category.ParentId,
                    category.Number,
                    category.State,
                    category.CreatedDate
                             );
                if (result == "exists")
                {
                    ModelState.AddModelError("", string.Format("Chuyên mục '{0}' đã tồn tại trên hệ thống.", category.Name));
                    AddViewData("ListCategory", BuildListCategory());
                    return(View("Create", category));
                }

                SetFlashMessage(string.Format("Thêm chuyên mục tin '{0}' thành công.", category.Name));
                return(RedirectToAction("Index"));
            }
            AddViewData("ListCategory", BuildListCategory());
            return(View("Create", category));
        }
Exemplo n.º 2
0
 public ActionResult OnEdit(NewsCategoryModels category)
 {
     if (ModelState.IsValid)
     {
         var result = NewsGroupService.Update(
             category.Id, category.Name,
             category.ParentId, category.Number,
             category.State, category.CreatedDate);
         if (result == "not_exists")
         {
             ModelState.AddModelError("", "Id không tồn tại trên hệ thống.");
             AddViewData("ListCategory", BuildListCategory());
             return(View("Edit", category));
         }
         SetFlashMessage(string.Format("Sửa chuyên mục '{0}' thành công.", category.Name));
         return(RedirectToAction("Index"));
     }
     AddViewData("ListCategory", BuildListCategory());
     return(View("Edit", category));
 }
Exemplo n.º 3
0
        public ActionResult Edit(int id)
        {
            var categoryItem = NewsGroupService.Find(id);

            if (categoryItem == null)
            {
                return(RedirectToAction("Index"));
            }
            AddViewData("ListCategory", BuildListCategory());
            var categoryModel = new NewsCategoryModels
            {
                Id       = categoryItem.ID,
                Name     = categoryItem.Name,
                ParentId = categoryItem.Parent ?? 0,
                Number   = categoryItem.Number ?? 0,
                State    = categoryItem.Status.HasValue && categoryItem.Status.Value
            };

            return(View("Edit", categoryModel));
        }