Esempio n. 1
0
        public ActionResult Create(Category category)
        {
            if (ModelState.IsValid)
            {
                if (!category.Image.IsNullOrWhiteSpace() && category.Image.Contains("/"))
                {
                    category.Image = splitImage(Request["Image"]);
                }
                if (!category.Icon.IsNullOrWhiteSpace() && category.Icon.Contains("/"))
                {
                    category.Icon = splitImage(Request["Icon"]);
                }

                if (dao.Insert(category))
                {
                    SetAlert("Add Category success", "success");
                    return(RedirectToAction("Index", "Categories"));
                }
                else
                {
                    ModelState.AddModelError("", "Insert Failed");
                }
            }
            return(View());
        }
Esempio n. 2
0
        public ActionResult Create(Category tag)
        {
            SetViewBag();
            var dao    = new CategoriesDao();
            var result = dao.ListAll();

            if (ModelState.IsValid)
            {
                long id = dao.Insert(tag);
                if (id > 0)
                {
                    // chuyển hướng trang về admin/User/index

                    return(RedirectToAction("Index", "Category", result));
                }
                else
                {
                    ModelState.AddModelError("", "Thêm danh muc không thành công");
                }
            }
            return(View("Create"));
        }