Ejemplo n.º 1
0
        public List <DanhMucModel> GetDanhMucCon(List <DanhMucModel> lstAll, DanhMucModel node)
        {
            var ds_con = lstAll.Where(ds => ds.ID_DM_Cha == node.ID_DM).ToList();

            if (ds_con.Count == 0)
            {
                return(null);
            }
            for (int i = 0; i < ds_con.Count; i++)
            {
                var con = GetDanhMucCon(lstAll, ds_con[i]);
                ds_con[i].DM_Con = con;
            }
            return(ds_con.OrderBy(s => s.Seq_Num).ToList());
        }
Ejemplo n.º 2
0
        //Danh muc
        public ActionResult DanhMuc(int page = 1, int pagesize = 9)
        {
            if (CheckQuyen() == 1)
            {
                List <DanhMuc> lisdm = new DanhMucModel().GetData();



                return(View(lisdm.ToPagedList(page, pagesize)));
            }

            else
            {
                return(Redirect("/NhanVien/DangNhap"));
            }
        }
        public ActionResult EditSubCat(DanhMucModel model)
        {
            if (Session["Admin"] == null && Session["SA"] == null)
                RedirectToAction("Index", "Login");
            List<String> error = new List<string>();

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

                model.danhmuc.ID_DanhMucCha = model.id;
                db.Entry(model.danhmuc).State = EntityState.Modified;
                try
                {

                    db.SaveChanges();
                    error.Add("Edit category success.");
                    ViewBag.error = error;
                }
                catch (Exception e)
                {
                    error.Add(e.ToString());
                    ViewBag.error = error;
                }
            }
            List<tbl_DanhMuc> lst = db.tbl_DanhMuc.Where(m => m.ID_DanhMucCha == null).ToList();
            model.danhmuccha = lst;
            return View(model);
        }
 public ActionResult EditSubCat(int? id)
 {
     if (Session["Admin"] == null && Session["SA"] == null)
         RedirectToAction("Index", "Login");
     ViewBag.error = "";
     if (id == null)
     {
         return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
     }
     DanhMucModel model = new DanhMucModel();
     tbl_DanhMuc dm = db.tbl_DanhMuc.Find(id);
     if (dm == null)
     {
         return HttpNotFound();
     }
     try
     {
         List<tbl_DanhMuc> lst = db.tbl_DanhMuc.Where(m => m.ID_DanhMucCha == null).ToList();
         model.danhmuc = dm;
         model.id = (int)dm.ID_DanhMucCha;
         model.danhmuccha = lst;
     }
     catch
     {
         ViewBag.error = "NULL";
     }
     return View(model);
 }
        public ActionResult AddSubCat(DanhMucModel dm)
        {
            if (Session["Admin"] == null && Session["SA"] == null)
                RedirectToAction("Index", "Login");

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

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

            try
            {
                dm.danhmuc.ID_DanhMucCha = dm.id;
                db.tbl_DanhMuc.Add(dm.danhmuc);
                db.SaveChanges();
                error.Add("Create SubCategory success.");
                ViewBag.error = error;
                DanhMucModel model = new DanhMucModel();
                model.danhmuccha = db.tbl_DanhMuc.Where(m => m.ID_DanhMucCha == null).ToList();
                return View(model);
            }
            catch
            {
                error.Add("Create SubCategory fail.");
                ViewBag.error = error;
                DanhMucModel model = new DanhMucModel();
                model.danhmuccha = db.tbl_DanhMuc.Where(m => m.ID_DanhMucCha == null).ToList();
                return View(model);
            }
        }
 public ActionResult AddSubCat()
 {
     if (Session["Admin"] == null && Session["SA"] == null)
         RedirectToAction("Index", "Login");
     ViewBag.error = "";
     DanhMucModel dm = new DanhMucModel();
     dm.danhmuccha = db.tbl_DanhMuc.Where(m => m.ID_DanhMucCha == null).ToList();
     return View(dm);
 }