public ActionResult Create(MPost mPost)
 {
     if (ModelState.IsValid)
     {
         String strSlug = XString.ToAscii(mPost.Title);
         mPost.Slug       = strSlug;
         mPost.Type       = "post";
         mPost.Created_at = DateTime.Now;
         mPost.Created_by = 1 /*int.Parse(Session["Admin_ID"].ToString());*/;
         mPost.Updated_at = DateTime.Now;
         mPost.Updated_by = 1 /*int.Parse(Session["Admin_ID"].ToString());*/;
         var file = Request.Files["Image"];
         if (file != null && file.ContentLength > 0)
         {
             String filename = strSlug + file.FileName.Substring(file.FileName.LastIndexOf("."));
             mPost.Image = filename;
             String Strpath = Path.Combine(Server.MapPath("~/Content/Path/post/"), filename);
             file.SaveAs(Strpath);
         }
         db.Post.Add(mPost);
         db.SaveChanges();
         Thongbao.set_flash("Đã thêm bài viết mới!", "success");
         return(RedirectToAction("Index"));
     }
     return(View(mPost));
 }
        public ActionResult Edit(MPost mPost)
        {
            MTopic mTopic = new MTopic();

            ViewBag.ListTopic = new SelectList(db.Topic.ToList(), "ID", "Name", 0);
            if (ModelState.IsValid)
            {
                String strSlug = XString.ToAscii(mPost.Title);
                mPost.Slug       = strSlug;
                mPost.Type       = "post";
                mPost.Updated_at = DateTime.Now;
                mPost.Updated_by = 1 /*int.Parse(Session["Admin_ID"].ToString());*/;
                var file = Request.Files["Image"];
                if (file != null && file.ContentLength > 0)
                {
                    String filename = strSlug + file.FileName.Substring(file.FileName.LastIndexOf("."));
                    mPost.Image = filename;
                    String Strpath = Path.Combine(Server.MapPath("~/Content/Path/post/"), filename);
                    file.SaveAs(Strpath);
                }

                db.Entry(mPost).State = EntityState.Modified;
                db.SaveChanges();
                Thongbao.set_flash("Đã cập nhật lại bài viết!", "success");
                return(RedirectToAction("Index"));
            }
            return(View(mPost));
        }
Example #3
0
 public PostEditPage(MPost post)
 {
     InitializeComponent();
     BindingContext = PostEditVM = new PostEditViewModel {
         Post = post
     };
 }
        public ActionResult Edit(MPost mPost)
        {
            if (ModelState.IsValid)
            {
                String strSlug = XString.ToAscii(mPost.Title);
                mPost.Slug       = strSlug;
                mPost.Type       = "page";
                mPost.Updated_at = DateTime.Now;
                mPost.Updated_by = int.Parse(Session["Admin_ID"].ToString());
                var file = Request.Files["Image"];
                if (file != null && file.ContentLength > 0)
                {
                    String filename = strSlug + file.FileName.Substring(file.FileName.LastIndexOf("."));
                    mPost.Image = filename;
                    String Strpath = Path.Combine(Server.MapPath("~/Content/Library/images/page/"), filename);
                    file.SaveAs(Strpath);
                }

                db.Entry(mPost).State = EntityState.Modified;
                db.SaveChanges();
                Thongbao.set_flash("Đã cập nhật lại nội dung trang đơn!", "success");
                return(RedirectToAction("Index"));
            }
            return(View(mPost));
        }
        public MPost Delete(int id)
        {
            MPost entity = _posts.Where(i => i.PostId == id).FirstOrDefault();

            _posts.Remove(entity);

            return(entity);
        }
        public ActionResult DeleteConfirmed(int id)
        {
            MPost mPost = db.Post.Find(id);

            db.Post.Remove(mPost);
            db.SaveChanges();
            Thongbao.set_flash("Đã xóa vĩnh viễn", "danger");
            return(RedirectToAction("Trash"));
        }
        public JsonResult changeStatus(int id)
        {
            MPost mPost = db.Post.Find(id);

            mPost.Status = (mPost.Status == 1) ? 2 : 1;

            mPost.Updated_at      = DateTime.Now;
            mPost.Updated_by      = 1 /*int.Parse(Session["Admin_ID"].ToString());*/;
            db.Entry(mPost).State = EntityState.Modified;
            db.SaveChanges();
            return(Json(new { Status = mPost.Status }));
        }
        public ActionResult Undo(int?id)
        {
            MPost mPost = db.Post.Find(id);

            mPost.Status = 2;

            mPost.Updated_at      = DateTime.Now;
            mPost.Updated_by      = 1 /*int.Parse(Session["Admin_ID"].ToString());*/;
            db.Entry(mPost).State = EntityState.Modified;
            db.SaveChanges();
            Thongbao.set_flash("Khôi phục thành công!" + " ID = " + id, "success");
            return(RedirectToAction("Trash"));
        }
        public ActionResult DelTrash(int?id)
        {
            MPost mPost = db.Post.Find(id);

            mPost.Status = 0;

            mPost.Updated_at      = DateTime.Now;
            mPost.Updated_by      = 1 /*int.Parse(Session["Admin_ID"].ToString());*/;
            db.Entry(mPost).State = EntityState.Modified;
            db.SaveChanges();
            Thongbao.set_flash("Đã chuyển vào thùng rác!" + " ID = " + id, "success");
            return(RedirectToAction("Index"));
        }
        public MPost Insert(PostInsertRequest request)
        {
            MPost newPost = new MPost
            {
                AccountId   = request.AccountId,
                Content     = request.Content,
                PublishDate = request.PublishDate,
                Title       = request.Title
            };

            _posts.Add(newPost);

            return(newPost);
        }
        // Edit
        public ActionResult Edit(int?id)
        {
            MTopic mTopic = new MTopic();

            ViewBag.ListTopic = new SelectList(db.Topic.ToList(), "ID", "Name", 0);
            MPost mPost = db.Post.Find(id);

            if (mPost == null)
            {
                Thongbao.set_flash("Không tồn tại bài viết!", "warning");
                return(RedirectToAction("Index", "Post"));
            }
            return(View(mPost));
        }
    /// <summary>
    /// Sends the score to leader board with my http.
    /// </summary>
    /// <returns>The score to leader board with my http.</returns>
    /// <param name="_username">Username.</param>
    /// <param name="_score">Score.</param>
    public IEnumerator SendScoreToLeaderBoardWithMyHttp(string _username, int _score)
    {
        MPost post = new MPost(_username, _score);

        Request request = new Request(HConst.LeaderBoardApi)
                          .AddHeader("Test-Header", "test")
                          .Post(RequestBody.From <MPost>(post));

        Client http = new Client();

        yield return(http.Send(request));

        ProcessResult(http);
    }
        public MPost Update(int id, PostUpdateRequest request)
        {
            var found = _posts.Where(i => i.PostId == id).FirstOrDefault();

            MPost updatePost = new MPost
            {
                PostId      = found.PostId,
                AccountId   = found.AccountId,
                Content     = found.Content,
                PublishDate = found.PublishDate,
                Title       = found.Title
            };

            return(found);
        }
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                Thongbao.set_flash("Không tồn tại bài viết!", "warning");
                return(RedirectToAction("Index", "Post"));
            }
            MPost mPost = db.Post.Find(id);

            if (mPost == null)
            {
                Thongbao.set_flash("Không tồn tại bài viết!", "warning");
                return(RedirectToAction("Index", "Post"));
            }
            return(View(mPost));
        }
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                Thongbao.set_flash("Không tồn tại trang đơn!", "warning");
                return(RedirectToAction("Index", "Page"));
            }
            MPost mPost = db.Post.Find(id);

            if (mPost == null)
            {
                Thongbao.set_flash("Không tồn tại trang đơn!", "warning");
                return(RedirectToAction("Index", "Page"));
            }
            return(View(mPost));
        }
        public ActionResult Index(FormCollection data)
        {
            ViewBag.ListCat   = db.Category.Where(m => m.Status == 1).ToList();
            ViewBag.ListTopic = db.Topic.Where(m => m.Status == 1).ToList();
            ViewBag.ListPage  = db.Post.Where(m => m.Status == 1 && m.Type == "page").ToList();

            if (!String.IsNullOrEmpty(data["AddCat"]))
            {
                if (!String.IsNullOrEmpty(data["itemCat"]))
                {
                    var itemcat = data["itemCat"];
                    var arr     = itemcat.Split(',');
                    int count   = 0;
                    foreach (var i in arr)
                    {
                        int       id        = int.Parse(i);
                        MCategory mCategory = db.Category.Find(id);
                        MMenu     mMenu     = new MMenu();
                        mMenu.Name       = mCategory.Name;
                        mMenu.Link       = mCategory.Slug;
                        mMenu.Type       = "category";
                        mMenu.TableID    = id;
                        mMenu.Orders     = 1;
                        mMenu.Positon    = data["Position"];
                        mMenu.ParentID   = 0;
                        mMenu.Status     = 2;
                        mMenu.Created_at = DateTime.Now;
                        mMenu.Updated_by = 1 /*int.Parse(Session["Admin_ID"].ToString());*/;
                        mMenu.Updated_at = DateTime.Now;
                        mMenu.Updated_by = 1 /*int.Parse(Session["Admin_ID"].ToString());*/;
                        db.Menu.Add(mMenu);
                        db.SaveChanges();
                        count++;
                    }
                    Thongbao.set_flash("Đã thêm " + count + " menu mới!", "success");
                }
                else
                {
                    Thongbao.set_flash("Chưa chọn menu cần thêm!", "warning");
                }
            }
            if (!String.IsNullOrEmpty(data["AddTopic"]))
            {
                if (!String.IsNullOrEmpty(data["itemTopic"]))
                {
                    var itemtopic = data["itemTopic"];
                    var arr       = itemtopic.Split(',');
                    int count     = 0;
                    foreach (var i in arr)
                    {
                        int    id     = int.Parse(i);
                        MTopic mTopic = db.Topic.Find(id);
                        MMenu  mMenu  = new MMenu();
                        mMenu.Name       = mTopic.Name;
                        mMenu.Link       = mTopic.Slug;
                        mMenu.Type       = "topic";
                        mMenu.TableID    = id;
                        mMenu.Orders     = 1;
                        mMenu.Positon    = data["Position"];
                        mMenu.ParentID   = 0;
                        mMenu.Status     = 2;
                        mMenu.Created_at = DateTime.Now;
                        mMenu.Updated_by = 1 /*int.Parse(Session["Admin_ID"].ToString());*/;
                        mMenu.Updated_at = DateTime.Now;
                        mMenu.Updated_by = 1 /*int.Parse(Session["Admin_ID"].ToString());*/;
                        db.Menu.Add(mMenu);
                        db.SaveChanges();
                        count++;
                    }
                    Thongbao.set_flash("Đã thêm " + count + " menu mới!", "success");
                }
                else
                {
                    Thongbao.set_flash("Chưa chọn menu cần thêm!", "warning");
                }
            }
            if (!String.IsNullOrEmpty(data["AddPage"]))
            {
                if (!String.IsNullOrEmpty(data["itemPage"]))
                {
                    var itempage = data["itemPage"];
                    var arr      = itempage.Split(',');
                    int count    = 0;
                    foreach (var i in arr)
                    {
                        int   id    = int.Parse(i);
                        MPost mPost = db.Post.Find(id);
                        MMenu mMenu = new MMenu();
                        mMenu.Name       = mPost.Title;
                        mMenu.Link       = mPost.Slug;
                        mMenu.Type       = "page";
                        mMenu.TableID    = id;
                        mMenu.Orders     = 1;
                        mMenu.Positon    = data["Position"];
                        mMenu.ParentID   = 0;
                        mMenu.Status     = 2;
                        mMenu.Created_at = DateTime.Now;
                        mMenu.Updated_by = 1 /*int.Parse(Session["Admin_ID"].ToString());*/;
                        mMenu.Updated_at = DateTime.Now;
                        mMenu.Updated_by = 1 /*int.Parse(Session["Admin_ID"].ToString());*/;
                        db.Menu.Add(mMenu);
                        db.SaveChanges();
                        count++;
                    }
                    Thongbao.set_flash("Đã thêm " + count + " menu mới!", "success");
                }
                else
                {
                    Thongbao.set_flash("Chưa chọn menu cần thêm!", "warning");
                }
            }
            if (!String.IsNullOrEmpty(data["AddCustom"]))
            {
                if (!String.IsNullOrEmpty(data["name"]) && !String.IsNullOrEmpty(data["link"]))
                {
                    MMenu mMenu = new MMenu();
                    mMenu.Name       = data["name"];
                    mMenu.Link       = data["link"];
                    mMenu.Type       = "custom";
                    mMenu.Orders     = 1;
                    mMenu.Positon    = data["Position"];
                    mMenu.ParentID   = 0;
                    mMenu.Status     = 2;
                    mMenu.Created_at = DateTime.Now;
                    mMenu.Updated_by = 1 /*int.Parse(Session["Admin_ID"].ToString());*/;
                    mMenu.Updated_at = DateTime.Now;
                    mMenu.Updated_by = 1 /*int.Parse(Session["Admin_ID"].ToString());*/;
                    db.Menu.Add(mMenu);
                    db.SaveChanges();
                    Thongbao.set_flash("Đã thêm 1 menu mới!", "success");
                }
                else
                {
                    Thongbao.set_flash("Vui lòng nhập tên menu và link!", "warning");
                }
            }

            return(View(db.Menu.Where(m => m.Status != 0).ToList()));
        }