コード例 #1
0
        public ActionResult Create(FormCollection collection, Mpost mpost)
        {
            int     user_id = (!Session["user_id"].Equals("")) ? Convert.ToInt32(Session["user_id"].ToString()) : 1;
            XString str     = new XString();

            if (ModelState.IsValid)
            {
                mpost.TopId      = collection["ListTopics"];
                mpost.Slug       = str.ToAscii(mpost.Title);
                mpost.Created_at = DateTime.Now;
                mpost.Created_by = 1;
                mpost.Updated_at = DateTime.Now;
                mpost.Updated_by = 1;
                var file = Request.Files["fileimg"];
                if (file != null && file.ContentLength > 0)
                {
                    mpost.Img = file.FileName.ToString();
                    string path = System.IO.Path.Combine(Server.MapPath("~/Images/product/"), file.FileName.ToString());
                    file.SaveAs(path);
                    db.Posts.Add(mpost);
                    db.SaveChanges();
                }
                return(RedirectToAction("Index"));
            }
            ViewBag.ListTopics = new SelectList(db.Topics, "Id", "Name");
            return(View(mpost));
        }
コード例 #2
0
 public ActionResult Create(Mpost mpost)
 {
     if (ModelState.IsValid)
     {
         HttpPostedFileBase file;
         var    namecateDb = db.topics.Where(m => m.ID == mpost.topid).First();
         string slug       = Mystring.ToSlug(mpost.title.ToString());
         string namecate   = Mystring.ToStringNospace(namecateDb.name);
         file = Request.Files["img"];
         string filename      = file.FileName.ToString();
         string ExtensionFile = Mystring.GetFileExtension(filename);
         string namefilenew   = namecate + "/" + slug + "." + ExtensionFile;
         var    path          = Path.Combine(Server.MapPath("~/public/images/post/"), namefilenew);
         var    folder        = Server.MapPath("~/public/images/" + namecate);
         if (!Directory.Exists(folder))
         {
             Directory.CreateDirectory(folder);
         }
         file.SaveAs(path);
         mpost.img        = namefilenew;
         mpost.slug       = slug;
         mpost.type       = "Post";
         mpost.created_at = DateTime.Now;
         mpost.updated_at = DateTime.Now;
         mpost.created_by = int.Parse(Session["Admin_id"].ToString());
         mpost.updated_by = int.Parse(Session["Admin_id"].ToString());
         db.posts.Add(mpost);
         db.SaveChanges();
         Message.set_flash("Thêm thành công", "success");
         return(RedirectToAction("Index"));
     }
     ViewBag.listTopic = db.topics.Where(m => m.status != 0).ToList();
     Message.set_flash("Thêm Thất Bại", "danger");
     return(View(mpost));
 }
コード例 #3
0
        public ActionResult DeleteConfirmed(int id)
        {
            Mpost mpost = db.Posts.Find(id);

            db.Posts.Remove(mpost);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #4
0
        public ActionResult Retrash(int id)
        {
            Mpost mpost = db.Posts.Find(id);

            mpost.Status          = 2;
            db.Entry(mpost).State = EntityState.Modified;
            db.SaveChanges();
            return(RedirectToAction("Trash", "Post"));
        }
コード例 #5
0
        public ActionResult deleteTrash(int id)
        {
            Mpost mpost = db.posts.Find(id);

            db.posts.Remove(mpost);
            db.SaveChanges();
            Message.set_flash("Đã xóa vĩnh viễn 1 sản phẩm", "success");
            return(RedirectToAction("trash"));
        }
コード例 #6
0
        public ActionResult Retrash(int id)
        {
            Mpost mpost = db.posts.Find(id);

            mpost.status          = 2;
            mpost.updated_at      = DateTime.Now;
            mpost.updated_by      = int.Parse(Session["Admin_id"].ToString());
            db.Entry(mpost).State = EntityState.Modified;
            db.SaveChanges();
            Message.set_flash("khôi phục thành công", "success");
            return(RedirectToAction("trash"));
        }
コード例 #7
0
        public ActionResult Status(int id)
        {
            Mpost mpost = db.posts.Find(id);

            mpost.status          = (mpost.status == 1) ? 2 : 1;
            mpost.updated_at      = DateTime.Now;
            mpost.updated_by      = int.Parse(Session["Admin_id"].ToString());
            db.Entry(mpost).State = EntityState.Modified;
            db.SaveChanges();
            Message.set_flash("Thay đổi trang thái thành công", "success");
            return(RedirectToAction("Index"));
        }
コード例 #8
0
        // GET: Admin/Post/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Mpost mpost = db.Posts.Find(id);

            if (mpost == null)
            {
                return(HttpNotFound());
            }
            return(View(mpost));
        }
コード例 #9
0
        // GET: Admin/Post/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Mpost mpost = db.Posts.Find(id);

            ViewBag.ListTopics = new SelectList(db.Topics, "Id", "Name");
            if (mpost == null)
            {
                return(HttpNotFound());
            }
            return(View(mpost));
        }
コード例 #10
0
        public string ShowStatus(int id)
        {
            string strStatus = "";
            Mpost  mpost     = db.Posts.Find(id);

            if (mpost.Status == 1)
            {
                strStatus = "<span class='btn btn-info btn-sm' ><i class='fas fa-toggle-on'></i>TT</span>";
            }
            else
            {
                strStatus = "<span class='btn btn-danger btn-sm' ><i class=' fas fa-toggle-off'></i>TT</span>";
            }
            return(strStatus);
        }
コード例 #11
0
        // GET: Admin/Post/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Mpost mpost = db.posts.Find(id);

            if (mpost == null)
            {
                return(HttpNotFound());
            }
            ViewBag.listTopic = db.topics.Where(m => m.status != 0).ToList();
            return(View(mpost));
        }
コード例 #12
0
        public ActionResult Status(int id)
        {
            Mpost mpost = db.Posts.Find(id);

            if (mpost.Status == 1)
            {
                mpost.Status = 2;
            }
            else
            {
                mpost.Status = 1;
            }
            db.Entry(mpost).State = EntityState.Modified;
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #13
0
        public ActionResult Index(FormCollection data)
        {
            if (!string.IsNullOrEmpty(data["ADDPAGE"]))
            {
                var itemcatt = data["itempage"];
                if (itemcatt == null)
                {
                    Message.set_flash("Bạn chưa chọn Mà", "danger");
                    return(RedirectToAction("index"));
                }
                var arrcat = itemcatt.Split(',');
                foreach (var rcat in arrcat)
                {
                    int   id   = int.Parse(rcat);
                    Mpost post = db.posts.Find(id);
                    Mmenu menu = new Mmenu();
                    menu.name       = post.title;
                    menu.link       = post.slug;
                    menu.position   = data["position"];
                    menu.type       = "menu";
                    menu.tableid    = 2;
                    menu.parentid   = 0;
                    menu.orders     = 1;
                    menu.created_at = DateTime.Now;
                    menu.updated_at = DateTime.Now;
                    menu.created_by = int.Parse(Session["Admin_id"].ToString());
                    menu.updated_by = int.Parse(Session["Admin_id"].ToString());
                    menu.status     = 1;
                    db.Menus.Add(menu);
                    db.SaveChanges();
                    Message.set_flash("Thêm thành công", "success");
                }
            }

            if (!string.IsNullOrEmpty(data["THEMCATE"]))
            {
                var itemcatt = data["itemCat"];
                if (itemcatt == null)
                {
                    Message.set_flash("Bạn chưa chọn Mà", "danger");
                    return(RedirectToAction("index"));
                }
                var arrcat = itemcatt.Split(',');
                foreach (var rcat in arrcat)
                {
                    int       id        = int.Parse(rcat);
                    Mcategory mcategory = db.Categorys.Find(id);
                    Mmenu     menu      = new Mmenu();
                    menu.name       = mcategory.name;
                    menu.link       = "loaiSP/" + mcategory.slug;
                    menu.position   = data["position"];
                    menu.type       = "menu";
                    menu.tableid    = 2;
                    menu.parentid   = 0;
                    menu.orders     = 1;
                    menu.created_at = DateTime.Now;
                    menu.updated_at = DateTime.Now;
                    menu.created_by = int.Parse(Session["Admin_id"].ToString());
                    menu.updated_by = int.Parse(Session["Admin_id"].ToString());
                    menu.status     = 1;
                    db.Menus.Add(menu);
                    db.SaveChanges();
                    Message.set_flash("Thêm thành công", "success");
                }
            }
            if (!string.IsNullOrEmpty(data["THEMTOPIC"]))
            {
                var itemcatt = data["itemtopic"];
                if (itemcatt == null)
                {
                    Message.set_flash("Bạn chưa chọn", "danger");
                    return(RedirectToAction("index"));
                }
                var arrcat = itemcatt.Split(',');
                foreach (var rcat in arrcat)
                {
                    int    id     = int.Parse(rcat);
                    Mtopic mtopic = db.topics.Find(id);
                    Mmenu  menu   = new Mmenu();
                    menu.name       = mtopic.name;
                    menu.link       = mtopic.slug;
                    menu.position   = data["position"];
                    menu.type       = "menu";
                    menu.tableid    = 2;
                    menu.parentid   = 0;
                    menu.orders     = 1;
                    menu.created_at = DateTime.Now;
                    menu.updated_at = DateTime.Now;
                    menu.created_by = int.Parse(Session["Admin_id"].ToString());
                    menu.updated_by = int.Parse(Session["Admin_id"].ToString());
                    menu.status     = 1;
                    db.Menus.Add(menu);
                    db.SaveChanges();
                    Message.set_flash("Thêm thành công", "success");
                }
            }
            if (!string.IsNullOrEmpty(data["THEMCUSS"]))
            {
                Mmenu menu = new Mmenu();
                menu.position   = data["position"];
                menu.name       = data["name"];
                menu.link       = data["link"];
                menu.type       = "menu";
                menu.tableid    = 2;
                menu.parentid   = 0;
                menu.orders     = 1;
                menu.created_at = DateTime.Now;
                menu.updated_at = DateTime.Now;
                menu.created_by = int.Parse(Session["Admin_id"].ToString());
                menu.updated_by = int.Parse(Session["Admin_id"].ToString());
                menu.status     = 1;
                db.Menus.Add(menu);
                db.SaveChanges();
                Message.set_flash("Thêm thành công", "success");
            }
            ViewBag.listCate  = db.Categorys.Where(m => m.status == 1).ToList();
            ViewBag.listTopic = db.topics.Where(m => m.status == 1).ToList();
            ViewBag.listPage  = db.posts.Where(m => m.status == 1 && m.type == "post").ToList();
            var list = db.Menus.Where(m => m.status > 0).ToList();

            return(View(list));
        }