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));
        }
        public ActionResult OnDelete(int id)
        {
            var result = NewsGroupService.Delete(id);

            SetFlashMessage(result == "ok" ?
                            "Xóa chuyên mục thành công." :
                            "Chuyên mục không tồn tại trên hệ thống.");
            return(RedirectToAction("Index"));
        }
        public ActionResult OnChangeState(int id)
        {
            var result = NewsGroupService.ChangeState(id);

            SetFlashMessage(result == "ok" ?
                            "Thay đổi trạng thái Chuyên mục thành công." :
                            "Chuyên mục không tồn tại trên hệ thống.");
            return(RedirectToAction("Index"));
        }
Beispiel #4
0
        public ActionResult OnCreate(NewsModels news)
        {
            if (ModelState.IsValid)
            {
                news.ImageUrl = news.Image != null?
                                news.Image.Upload() :
                                    news.ImageUrl;

                var newsItem = new News
                {
                    Title       = news.Title,
                    TypeID      = news.CategoryId,
                    Image       = news.ImageUrl,
                    Summary     = news.Summary,
                    Detail      = news.Detail,
                    Keyword     = news.Keyword,
                    Description = news.Description,
                    Order       = news.Order,
                    Hot         = news.IsFast,
                    Fast        = news.IsFast,
                    Featured    = news.IsFeatured,
                    Status      = news.Status,
                    Date        = news.CreatedAt,
                    Site        = news.Site
                };
                var result = NewsService.Insert(newsItem);
                if (result == Result.Exists)
                {
                    ModelState.AddModelError("", string.Format("Tin tức '{0}' đã tồn tại trên hệ thống.", news.Title));
                    ViewBag.ListCategory = BuildListCategory();
                    ViewBag.ListSite     = DataHelper.ListEnumType <NewsSiteEnum>();
                    return(View("Create", news));
                }
                SetFlashMessage(string.Format("Thêm tin tức '{0}' thành công.", news.Title));
                if (news.SaveList)
                {
                    return(RedirectToAction("Index"));
                }
                ModelState.Clear();
                ViewBag.ListCategory = BuildListCategory();
                ViewBag.ListSite     = DataHelper.ListEnumType <NewsSiteEnum>();
                return(View("Create", news.ResetValue()));
            }
            ViewBag.ListCategory = NewsGroupService.GetAll().Select
                                   (
                cate => new MutilCategoryItem
            {
                Name     = cate.Name,
                Id       = cate.ID,
                ParentId = cate.Parent
            }
                                   ).ToList();
            return(View("Create", news));
        }
Beispiel #5
0
 private List <MutilCategoryItem> BuildListCategory()
 {
     return(NewsGroupService.GetAll().Select
            (
                cate => new MutilCategoryItem
     {
         Name = cate.Name,
         Id = cate.ID,
         ParentId = cate.Parent
     }
            ).ToList());
 }
 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));
 }
        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));
        }
 public ActionResult Index()
 {
     return(View("Index", NewsGroupService.GetAll(false)));
 }