示例#1
0
        public ActionResult Create_EditCategory(loaisp sp)
        {
            loaisp lsp = new loaisp();

            if (Session["admin"] == null)
            {
                return(RedirectToAction("Login"));
            }
            if (sp.MaLoaiSP == 0)
            {
                sp.Url = sp.TenLoai.ToFriendlyUrl();
                db.loaisps.Add(sp);
                db.SaveChanges();
            }
            else
            {
                loaisp loaisp_ = db.loaisps.Find(sp.MaLoaiSP);
                loaisp_.TenLoai         = sp.TenLoai;
                loaisp_.Url             = sp.TenLoai.ToFriendlyUrl();
                loaisp_.Mota            = sp.Mota;
                db.Entry(loaisp_).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
            }
            return(RedirectToAction("Category"));
        }
示例#2
0
        public ActionResult DeleteLoaiSP(int?idloaisp)
        {
            if (Session["admin"] == null)
            {
                return(RedirectToAction("Login"));
            }

            loaisp ls = db.loaisps.Find(idloaisp);

            if (ls != null)
            {
                db.loaisps.Remove(ls);
                db.SaveChanges();
            }
            return(RedirectToAction("Category"));
        }