public ActionResult EditCat(tbl_DanhMuc dm, HttpPostedFileBase file)
        {
            if (Session["Admin"] == null && Session["SA"] == null)
                RedirectToAction("Index", "Login");
            List<String> error = new List<string>();

            if (dm.TenDanhMuc == null)
                error.Add("TenDanhMuc field is required.");
            if (dm.IsHot == null)
                error.Add("IsHot field is not set.");
            if (error.Count > 0)
            {
                ViewBag.error = error;
                return View();
            }
            if (ModelState.IsValid)
            {
                if (file == null)
                {
                    db.Entry(dm).State = EntityState.Modified;
                    try
                    {
                        if (dm.HinhAnh == null)
                        {
                            error.Add("HinhAnh is required.");
                            ViewBag.error = error;
                            return View();
                        }
                        db.SaveChanges();
                        error.Add("Edit category success.");
                        ViewBag.error = error;
                    }
                    catch (Exception)
                    {
                        error.Add("Have an error when create category.");
                        ViewBag.error = error;
                    }

                }
                else
                {
                    string pic = Path.GetFileName(file.FileName);
                    dm.HinhAnh = pic;
                    string path = Path.Combine(Server.MapPath("~/Content/Image/Website"), pic);
                    file.SaveAs(path);
                    db.Entry(dm).State = EntityState.Modified;
                    try
                    {
                        db.SaveChanges();
                        error.Add("Edit category success.");
                        ViewBag.error = error;
                    }
                    catch (Exception)
                    {
                        error.Add("Have an error when create category.");
                        ViewBag.error = error;
                    }
                }
            }
            return View();
        }
        public ActionResult AddSubCatMod(tbl_DanhMuc model)
        {
            if (Session["Mod"] == null)
                RedirectToAction("Index", "Login");
            string user = (string)Session["Mod"];
            List<String> error = new List<string>();

            if (model.TenDanhMuc == null)
                error.Add("TenDanhMuc field is required.");
            if (model.IsHot == null)
                error.Add("IsHot field is not set.");
            if (error.Count > 0)
            {
                ViewBag.error = error;
                return View();
            }
            if (ModelState.IsValid)
            {
                try
                {
                    tbl_Account MOD = db.tbl_Account.FirstOrDefault(m => m.Username.Equals(user));
                    model.ID_DanhMucCha = MOD.ID_DanhMuc;
                    db.tbl_DanhMuc.Add(model);
                    db.SaveChanges();
                    error.Add("Create Subcategory success.");
                    ViewBag.error = error;

                }
                catch (Exception)
                {
                    error.Add("Have an error while creating new category");
                    ViewBag.error = error;
                }

            }
            return View();
        }
        public ActionResult AddCat(tbl_DanhMuc dm, HttpPostedFileBase file)
        {
            if (Session["Admin"] == null && Session["SA"] == null)
                RedirectToAction("Index", "Login");

            List<String> error = new List<string>();

            if (dm.TenDanhMuc == null)
                error.Add("TenDanhMuc field is required.");
            if (dm.IsHot == null)
                error.Add("IsHot field is not set.");
            if (error.Count > 0)
            {
                ViewBag.error = error;
                return View();
            }

            if (ModelState.IsValid)
            {
                if (file != null)
                {
                    string pic = Path.GetFileName(file.FileName);
                    dm.HinhAnh = pic;
                    string path = Path.Combine(Server.MapPath("~/Content/Image/Website"), pic);
                    file.SaveAs(path);
                    int vitri = (int)db.tbl_DanhMuc.Max(m => m.ViTri);
                    dm.ViTri = vitri + 1;
                    db.tbl_DanhMuc.Add(dm);
                    db.SaveChanges();
                    error.Add("Create category success.");
                    ViewBag.error = error;
                    return View();
                }
                else
                {
                    error.Add("HinhAnh is not selected.");
                    ViewBag.error = error;
                    return View();
                }
            }
            return View();
        }
 public ActionResult AddSubCatMod()
 {
     if (Session["Admin"] == null)
         RedirectToAction("Index", "Login");
     ViewBag.error = "";
     tbl_DanhMuc dm = new tbl_DanhMuc();
     return View(dm);
 }
        public ActionResult EditSubCatMod(tbl_DanhMuc model)
        {
            if (Session["Mod"] == null)
                RedirectToAction("Index", "Login");
            List<String> error = new List<string>();

            if (model.TenDanhMuc == null)
                error.Add("TenDanhMuc field is required.");
            if (model.IsHot == null)
                error.Add("IsHot field is not set.");
            if (error.Count > 0)
            {
                ViewBag.error = error;
                return View(model);
            }
            if (ModelState.IsValid)
            {
                try
                {
                    db.Entry(model).State = EntityState.Modified;
                    db.SaveChanges();
                    error.Add("Edit category success.");
                    ViewBag.error = error;
                    // Sua tiep phan sub cat cua mod
                }
                catch (Exception)
                {
                    error.Add("Can not edit category.");
                    ViewBag.error = error;
                }
            }
            return View(model);
        }