Ejemplo n.º 1
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string username = Request.Cookies["userLoginSystem"].Value;
            var    acc      = AccountController.GetByUsername(username);
            int    cateID   = ViewState["cateID"].ToString().ToInt(0);
            int    PostID   = ViewState["ID"].ToString().ToInt(0);

            if (cateID > 0)
            {
                string PostTitle   = txtPostTitle.Text;
                string PostContent = pContent.Content;
                int    CategoryID  = hdfParentID.Value.ToInt();

                //Phần thêm ảnh đại diện sản phẩm
                string path      = "/uploads/images/";
                string PostImage = ListPostThumbnail.Value;
                if (PostThumbnailImage.UploadedFiles.Count > 0)
                {
                    foreach (UploadedFile f in PostThumbnailImage.UploadedFiles)
                    {
                        var o = path + PostID + '-' + convertToSlug(Path.GetFileName(f.FileName));
                        try
                        {
                            f.SaveAs(Server.MapPath(o));
                            PostImage = o;
                        }
                        catch { }
                    }
                }

                if (PostImage != ListPostThumbnail.Value)
                {
                    if (File.Exists(Server.MapPath(ListPostThumbnail.Value)))
                    {
                        File.Delete(Server.MapPath(ListPostThumbnail.Value));
                    }
                }

                // Delete Image Gallery

                string deleteImageGallery = hdfDeleteImageGallery.Value;

                if (deleteImageGallery != "")
                {
                    string[] deletelist = deleteImageGallery.Split(',');

                    for (int i = 0; i < deletelist.Length - 1; i++)
                    {
                        var img = PostImageController.GetByID(Convert.ToInt32(deletelist[i]));
                        if (img != null)
                        {
                            var post = PostController.GetByID(PostID);

                            // Delete image
                            if (!string.IsNullOrEmpty(img.Image) && img.Image != post.Image)
                            {
                                string fileImage = Server.MapPath(img.Image);
                                File.Delete(fileImage);
                            }
                            string delete = PostImageController.Delete(img.ID);
                        }
                    }
                }

                // Update product

                string kq = PostController.Update(PostID, PostTitle, PostContent, PostImage, ddlFeatured.SelectedValue.ToInt(), CategoryID, 1, username, DateTime.Now);

                // Upload image gallery

                if (UploadImages.HasFiles)
                {
                    foreach (HttpPostedFile uploadedFile in UploadImages.PostedFiles)
                    {
                        var o = path + PostID + '-' + convertToSlug(Path.GetFileName(uploadedFile.FileName));
                        uploadedFile.SaveAs(Server.MapPath(o));
                        PostImageController.Insert(PostID, o, username, DateTime.Now);
                    }
                }


                if (kq.ToInt(0) > 0)
                {
                    PJUtils.ShowMessageBoxSwAlert("Cập nhật sản phẩm thành công", "s", true, Page);
                }
            }
        }
Ejemplo n.º 2
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string   username    = Request.Cookies["usernameLoginSystem"].Value;
            var      acc         = AccountController.GetByUsername(username);
            DateTime currentDate = DateTime.Now;
            int      cateID      = hdfParentID.Value.ToInt();

            if (cateID > 0)
            {
                string Title    = txtTitle.Text.Trim();
                string PostSlug = Slug.ConvertToSlug(txtSlug.Text.Trim());
                string Content  = pContent.Content.ToString();

                var newPost = new tbl_Post()
                {
                    Title        = Title,
                    Content      = Content,
                    Image        = "",
                    Featured     = ddlFeatured.SelectedValue.ToInt(),
                    CategoryID   = cateID,
                    Status       = 1,
                    CreatedBy    = acc.Username,
                    CreatedDate  = currentDate,
                    ModifiedBy   = acc.Username,
                    ModifiedDate = currentDate,
                    WebPublish   = false,
                    WebUpdate    = currentDate,
                    Slug         = PostSlug
                };

                var post = PostController.Insert(newPost);

                if (post != null)
                {
                    //Phần thêm ảnh đại diện
                    string path  = "/uploads/images/posts/";
                    string Image = "";
                    if (ProductThumbnailImage.UploadedFiles.Count > 0)
                    {
                        foreach (UploadedFile f in ProductThumbnailImage.UploadedFiles)
                        {
                            var o = path + "post-" + post.ID + "-" + Slug.ConvertToSlug(Path.GetFileName(f.FileName), isFile: true);
                            try
                            {
                                f.SaveAs(Server.MapPath(o));
                                Image = o;
                            }
                            catch { }
                        }
                    }

                    string updateImage = PostController.UpdateImage(post.ID, Image);

                    //Phần thêm thư viện ảnh
                    string IMG = "";
                    if (hinhDaiDien.UploadedFiles.Count > 0)
                    {
                        foreach (UploadedFile f in hinhDaiDien.UploadedFiles)
                        {
                            var o = path + "post-" + post.ID + "-" + Slug.ConvertToSlug(Path.GetFileName(f.FileName), isFile: true);
                            try
                            {
                                f.SaveAs(Server.MapPath(o));
                                IMG = o;
                                PostImageController.Insert(post.ID, IMG, username, currentDate);
                            }
                            catch { }
                        }
                    }

                    PJUtils.ShowMessageBoxSwAlertCallFunction("Tạo bài viết thành công", "s", true, "redirectTo(" + post.ID + ")", Page);
                }
            }
        }
Ejemplo n.º 3
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string username = Request.Cookies["usernameLoginSystem"].Value;
            var    acc      = AccountController.GetByUsername(username);
            int    cateID   = ViewState["cateID"].ToString().ToInt(0);
            int    PostID   = ViewState["ID"].ToString().ToInt(0);

            if (cateID > 0)
            {
                string Title      = txtTitle.Text.Trim();
                string PostSlug   = Slug.ConvertToSlug(txtSlug.Text.Trim());
                string Content    = pContent.Content.ToString();
                int    CategoryID = hdfParentID.Value.ToInt();

                //Phần thêm ảnh đại diện sản phẩm
                string path      = "/uploads/images/posts/";
                string PostImage = ListPostThumbnail.Value;
                if (PostThumbnailImage.UploadedFiles.Count > 0)
                {
                    foreach (UploadedFile f in PostThumbnailImage.UploadedFiles)
                    {
                        var o = path + "post-" + PostID + '-' + Slug.ConvertToSlug(Path.GetFileName(f.FileName), isFile: true);
                        try
                        {
                            f.SaveAs(Server.MapPath(o));
                            PostImage = o;
                        }
                        catch { }
                    }
                }

                // Delete Image Gallery
                string deleteImageGallery = hdfDeleteImageGallery.Value;
                if (deleteImageGallery != "")
                {
                    string[] deletelist = deleteImageGallery.Split(',');

                    for (int i = 0; i < deletelist.Length - 1; i++)
                    {
                        var img = PostImageController.GetByID(Convert.ToInt32(deletelist[i]));
                        if (img != null)
                        {
                            string delete = PostImageController.Delete(img.ID);
                        }
                    }
                }

                // Update post
                string kq = PostController.Update(PostID, Title, Content, PostImage, ddlFeatured.SelectedValue.ToInt(), CategoryID, 1, PostSlug, username, DateTime.Now);

                // Upload image gallery
                if (UploadImages.HasFiles)
                {
                    foreach (HttpPostedFile uploadedFile in UploadImages.PostedFiles)
                    {
                        var o = path + "post-" + PostID + '-' + Slug.ConvertToSlug(Path.GetFileName(uploadedFile.FileName), isFile: true);
                        uploadedFile.SaveAs(Server.MapPath(o));
                        PostImageController.Insert(PostID, o, username, DateTime.Now);
                    }
                }

                if (kq.ToInt(0) > 0)
                {
                    PJUtils.ShowMessageBoxSwAlertCallFunction("Cập nhật bài viết thành công", "s", true, "redirectTo(" + kq + ")", Page);
                }
            }
        }
Ejemplo n.º 4
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string   username    = Request.Cookies["usernameLoginSystem"].Value;
            var      acc         = AccountController.GetByUsername(username);
            DateTime currentDate = DateTime.Now;
            int      cateID      = hdfParentID.Value.ToInt();

            if (cateID > 0)
            {
                int    CategoryID   = ddlCategory.Value.ToInt();
                var    category     = PostPublicCategoryController.GetByID(CategoryID);
                string CategorySlug = category.Slug;
                string Title        = txtTitle.Text.Trim();
                string Slugs        = Slug.ConvertToSlug(txtSlug.Text.Trim());
                string Link         = txtLink.Text.Trim();
                string Content      = pContent.Content.ToString();
                string Summary      = HttpUtility.HtmlDecode(pSummary.Content.ToString());
                string Action       = ddlAction.SelectedValue.ToString();
                string ActionValue  = "";
                if (Action == "view_more")
                {
                    ActionValue = Slugs;
                }
                else if (Action == "show_web")
                {
                    ActionValue = Link;
                }
                bool AtHome   = ddlAtHome.SelectedValue.ToBool();
                bool IsPolicy = false;

                var newPostPublic = new PostPublic()
                {
                    CategoryID   = CategoryID,
                    CategorySlug = CategorySlug,
                    Title        = Title,
                    Thumbnail    = "",
                    Summary      = Summary,
                    Content      = Content,
                    Action       = Action,
                    ActionValue  = ActionValue,
                    AtHome       = AtHome,
                    IsPolicy     = IsPolicy,
                    CreatedDate  = currentDate,
                    CreatedBy    = acc.Username,
                    ModifiedDate = currentDate,
                    ModifiedBy   = acc.Username
                };

                var post = PostPublicController.Insert(newPostPublic);

                if (post != null)
                {
                    // Thêm ảnh đại diện
                    string path  = "/uploads/images/posts/";
                    string Image = "";
                    if (PostPublicThumbnailImage.UploadedFiles.Count > 0)
                    {
                        foreach (UploadedFile f in PostPublicThumbnailImage.UploadedFiles)
                        {
                            var o = path + "post-app-" + post.ID.ToString() + "-" + Slug.ConvertToSlug(Path.GetFileName(f.FileName), isFile: true);
                            try
                            {
                                f.SaveAs(Server.MapPath(o));
                                Image = o;
                            }
                            catch { }
                        }
                    }
                    string updateImage = PostPublicController.UpdateImage(post.ID, Image);

                    // Thêm thư viện ảnh
                    string IMG = "";
                    if (ImageGallery.UploadedFiles.Count > 0)
                    {
                        foreach (UploadedFile f in ImageGallery.UploadedFiles)
                        {
                            var o = path + "post-app-" + post.ID.ToString() + "-" + Slug.ConvertToSlug(Path.GetFileName(f.FileName), isFile: true);
                            try
                            {
                                f.SaveAs(Server.MapPath(o));
                                IMG = o;
                                PostPublicImageController.Insert(post.ID, IMG, username, currentDate);
                            }
                            catch { }
                        }
                    }

                    // Copy bài viết vào hệ thống gốc
                    if (ddlCopyToSystem.SelectedValue == "True" && post.Action == "view_more")
                    {
                        var categorySystem = PostCategoryController.GetByName(category.Name);
                        var postSystem     = new tbl_Post()
                        {
                            Title        = post.Title,
                            Content      = post.Content,
                            Image        = Image,
                            Featured     = 1,
                            CategoryID   = categorySystem != null ? categorySystem.ID : 0,
                            Status       = 1,
                            CreatedBy    = post.CreatedBy,
                            CreatedDate  = post.CreatedDate,
                            ModifiedBy   = post.ModifiedBy,
                            ModifiedDate = post.ModifiedDate,
                            WebPublish   = true,
                            WebUpdate    = post.CreatedDate,
                            Slug         = post.ActionValue
                        };

                        PostController.Insert(postSystem);

                        // Copy image
                        if (postSystem != null)
                        {
                            var imagePostPublic = PostPublicImageController.GetByPostID(post.ID);
                            if (imagePostPublic.Count > 0)
                            {
                                foreach (var item in imagePostPublic)
                                {
                                    PostImageController.Insert(postSystem.ID, item.Image, postSystem.CreatedBy, DateTime.Now);
                                }
                            }
                        }
                    }


                    // Tạo phiên bản cho wordpress
                    if (!String.IsNullOrEmpty(hdfPostVariants.Value))
                    {
                        JavaScriptSerializer serializer = new JavaScriptSerializer();
                        var variants = serializer.Deserialize <List <PostClone> >(hdfPostVariants.Value);
                        if (variants != null)
                        {
                            foreach (var item in variants)
                            {
                                var newPostClone = new PostClone()
                                {
                                    PostPublicID = post.ID,
                                    Web          = item.Web,
                                    PostWebID    = 0,
                                    CategoryID   = post.CategoryID,
                                    CategoryName = category.Name,
                                    Title        = !String.IsNullOrEmpty(item.Title) ? item.Title : post.Title,
                                    Summary      = post.Summary,
                                    Content      = post.Content,
                                    Thumbnail    = Image,
                                    CreatedDate  = post.CreatedDate,
                                    CreatedBy    = acc.Username,
                                    ModifiedDate = post.ModifiedDate,
                                    ModifiedBy   = acc.Username
                                };

                                PostCloneController.Insert(newPostClone);
                            }
                        }
                    }

                    PJUtils.ShowMessageBoxSwAlertCallFunction("Tạo bài viết thành công", "s", true, "redirectTo(" + post.ID.ToString() + ")", Page);
                }
            }
        }
Ejemplo n.º 5
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string   username    = Request.Cookies["userLoginSystem"].Value;
            var      acc         = AccountController.GetByUsername(username);
            DateTime currentDate = DateTime.Now;

            if (acc != null)
            {
                if (acc.RoleID == 0 || acc.RoleID == 1)
                {
                    int cateID = hdfParentID.Value.ToInt();
                    if (cateID > 0)
                    {
                        string Title   = txtTitle.Text.ToString();
                        string Content = pContent.Content.ToString();

                        string kq = PostController.Insert(Title, Content, "", ddlFeatured.SelectedValue.ToInt(), cateID, 1, acc.Username, currentDate);

                        //Phần thêm ảnh đại diện
                        string path  = "/uploads/images/";
                        string Image = "";
                        if (ProductThumbnailImage.UploadedFiles.Count > 0)
                        {
                            foreach (UploadedFile f in ProductThumbnailImage.UploadedFiles)
                            {
                                var o = path + kq + '-' + convertToSlug(Path.GetFileName(f.FileName));
                                try
                                {
                                    f.SaveAs(Server.MapPath(o));
                                    Image = o;
                                }
                                catch { }
                            }
                        }

                        string updateImage = PostController.UpdateImage(kq.ToInt(), Image);


                        //Phần thêm thư viện ảnh
                        string IMG = "";
                        if (hinhDaiDien.UploadedFiles.Count > 0)
                        {
                            foreach (UploadedFile f in hinhDaiDien.UploadedFiles)
                            {
                                var o = path + kq + '-' + convertToSlug(Path.GetFileName(f.FileName));
                                try
                                {
                                    f.SaveAs(Server.MapPath(o));
                                    IMG = o;
                                    PostImageController.Insert(kq.ToInt(), IMG, username, currentDate);
                                }
                                catch { }
                            }
                        }


                        if (kq.ToInt(0) > 0)
                        {
                            PJUtils.ShowMessageBoxSwAlertCallFunction("Tạo sản phẩm thành công", "s", true, "redirectTo(" + kq + ")", Page);
                        }
                    }
                }
            }
        }