public static string getAllPostImage(int id)
        {
            var           post   = PostController.GetByID(id);
            List <string> images = new List <string>();

            if (post != null)
            {
                images.Add(post.Image);

                // lấy ảnh sản phẩm từ thư viện

                var imagePost = PostImageController.GetByPostID(post.ID);

                if (imagePost != null)
                {
                    foreach (var img in imagePost)
                    {
                        images.Add(img.Image);
                    }
                }
            }
            JavaScriptSerializer serializer = new JavaScriptSerializer();

            return(serializer.Serialize(images.Distinct().ToList()));
        }
        public static string copyPostToApp(int id)
        {
            var post = PostController.GetByID(id);

            if (post != null)
            {
                var          postCategory       = PostCategoryController.GetByID(post.CategoryID.Value);
                PostCategory postPublicCategory = new PostCategory();
                if (postCategory != null)
                {
                    postPublicCategory = PostPublicCategoryController.GetByName(postCategory.Title);
                }

                var newPostPublic = new PostPublic()
                {
                    CategoryID   = postPublicCategory != null ? postPublicCategory.ID : 0,
                    CategorySlug = postPublicCategory != null ? postPublicCategory.Slug : "",
                    Title        = post.Title,
                    Thumbnail    = post.Image,
                    Summary      = "",
                    Content      = post.Content,
                    Action       = "view_more",
                    ActionValue  = PostPublicController.checkSlug(post.Slug),
                    AtHome       = false,
                    IsPolicy     = false,
                    CreatedDate  = DateTime.Now,
                    CreatedBy    = post.CreatedBy,
                    ModifiedDate = DateTime.Now,
                    ModifiedBy   = post.CreatedBy
                };

                var newpost = PostPublicController.Insert(newPostPublic);

                if (newpost != null)
                {
                    // Copy image gallery
                    var postImage = PostImageController.GetToCopyByPostID(post.ID);
                    if (postImage.Count > 0)
                    {
                        foreach (var img in postImage)
                        {
                            if (!string.IsNullOrEmpty(img.Image))
                            {
                                string newImage = PostPublicImageController.Insert(newpost.ID, img.Image, newpost.CreatedBy, DateTime.Now);
                            }
                        }
                    }

                    return(newpost.ID.ToString());
                }
            }

            return("false");
        }
        public static string deletePost(int id)
        {
            var    post   = PostController.GetByID(id);
            string result = "";

            if (post != null)
            {
                // Delete thumbnail image
                if (!string.IsNullOrEmpty(post.Image))
                {
                    string fileImage = HttpContext.Current.Server.MapPath(post.Image);
                    File.Delete(fileImage);
                }

                // Delete image gallery

                var postImage = PostImageController.GetByPostID(post.ID);

                if (postImage.Count > 0)
                {
                    foreach (var img in postImage)
                    {
                        if (!string.IsNullOrEmpty(img.Image))
                        {
                            string fileImage = HttpContext.Current.Server.MapPath(img.Image);
                            File.Delete(fileImage);

                            // Delete in database
                            string deletePostImage = PostImageController.Delete(img.ID);
                        }
                    }
                }


                string deletePost = PostController.Delete(id);

                if (!string.IsNullOrEmpty(deletePost))
                {
                    result = "success";
                }
                else
                {
                    result = "failed";
                }
            }
            else
            {
                result = "notfound";
            }

            return(result);
        }
        public static string copyPostInfo(int id)
        {
            var           post = PostController.GetByID(id);
            StringBuilder html = new StringBuilder();

            if (post != null)
            {
                html.Append("<p>" + post.Content + "</p>\r\n");
                html.Append("<p></p>\r\n");
            }

            return(html.ToString());
        }
Beispiel #5
0
        public void LoadData()
        {
            int id = Request.QueryString["id"].ToInt(0);

            if (id > 0)
            {
                var p = PostController.GetByID(id);
                if (p == null)
                {
                    PJUtils.ShowMessageBoxSwAlertError("Không tìm thấy bài viết " + id, "e", true, "/danh-sach-bai-viet", Page);
                }
                else
                {
                    this.Title = String.Format("{0} - Sửa bài viết", p.Title.ToTitleCase());

                    ViewState["ID"]           = id;
                    ViewState["cateID"]       = p.CategoryID;
                    hdfParentID.Value         = p.CategoryID.ToString();
                    ltrBack.Text              = "<a href='/xem-bai-viet?id=" + p.ID + "' class='btn primary-btn fw-btn not-fullwidth'><i class='fa fa-arrow-left' aria-hidden='true'></i> Trở về</a>";
                    ltrBack2.Text             = ltrBack.Text;
                    txtTitle.Text             = p.Title;
                    txtSlug.Text              = p.Slug;
                    pContent.Content          = p.Content;
                    ddlCategory.SelectedValue = p.CategoryID.ToString();
                    ddlFeatured.SelectedValue = p.Featured.ToString();

                    if (p.Image != null)
                    {
                        ListPostThumbnail.Value = p.Image;
                        PostThumbnail.ImageUrl  = p.Image;
                    }

                    var image = PostImageController.GetByPostID(id);
                    imageGallery.Text = "<ul class='image-gallery'>";
                    if (image != null)
                    {
                        foreach (var img in image)
                        {
                            imageGallery.Text += "<li><img src='" + img.Image + "'><a href='javascript:;' data-image-id='" + img.ID + "' onclick='deleteImageGallery($(this))' class='btn-delete'><i class='fa fa-times' aria-hidden='true'></i> Xóa hình</a></li>";
                        }
                    }
                    imageGallery.Text += "</ul>";

                    string PostInfo = "<p><strong>Ngày tạo</strong>: " + p.CreatedDate + "</p>";
                    PostInfo        += "<p><strong>Người viết</strong>: " + p.CreatedBy + "</p>";
                    PostInfo        += "<p><strong>Ngày cập nhật</strong>: " + p.ModifiedDate + "</p>";
                    PostInfo        += "<p><strong>Người cập nhật</strong>: " + p.ModifiedBy + "</p>";
                    ltrPostInfo.Text = PostInfo;
                }
            }
        }
Beispiel #6
0
        public void LoadData()
        {
            string username = Request.Cookies["usernameLoginSystem"].Value;
            var    acc      = AccountController.GetByUsername(username);

            int id = Request.QueryString["id"].ToInt(0);

            if (id > 0)
            {
                var p = PostController.GetByID(id);
                if (p == null)
                {
                    PJUtils.ShowMessageBoxSwAlertError("Không tìm thấy bài viết " + id, "e", true, "/danh-sach-bai-viet", Page);
                }
                else
                {
                    this.Title      = String.Format("{0} - Bài viết", p.Title.ToTitleCase());
                    ltrEditTop.Text = "";
                    if (acc.RoleID == 0 || acc.Username == "nhom_zalo502")
                    {
                        ltrEditTop.Text += "<a href='/sua-bai-viet?id=" + p.ID + "' class='btn primary-btn fw-btn not-fullwidth'><i class='fa fa-pencil-square-o' aria-hidden='true'></i> Chỉnh sửa</a>";
                    }
                    ltrEditTop.Text   += "<a href='javascript:;' onclick='copyPostInfo(" + p.ID + ");' class='btn primary-btn not-fullwidth print-invoice-merged'><i class='fa fa-files-o'></i> Copy nội dung</a>";
                    ltrEditTop.Text   += "<a href='javascript:;' onclick='getAllPostImage(" + p.ID + ");' class='btn primary-btn not-fullwidth print-invoice-merged'><i class='fa fa-cloud-download'></i> Tải hình</a>";
                    ltrEditTop.Text   += "<a href='javascript:;' onclick='copyPostToApp(" + p.ID + ");' class='btn primary-btn not-fullwidth print-invoice-merged'><i class='fa fa-cloud-download'></i> Copy vào App</a>";
                    ltrEditBottom.Text = ltrEditTop.Text;
                    ltrTitle.Text      = p.Title;
                    ltrContent.Text    = p.Content;

                    // thư viện ảnh
                    imageGallery.Text = "<ul class='image-gallery'>";
                    if (!String.IsNullOrEmpty(p.Image))
                    {
                        imageGallery.Text += "<li><img src='" + p.Image + "' /><a href='" + p.Image + "' download class='btn download-btn download-image h45-btn'><i class='fa fa-cloud-download'></i> Tải hình này</a></li>";
                    }
                    var image = PostImageController.GetByPostID(id);
                    if (image != null)
                    {
                        foreach (var img in image)
                        {
                            if (img.Image != p.Image)
                            {
                                imageGallery.Text += "<li><img src='" + img.Image + "' /><a href='" + img.Image + "' download class='btn download-btn download-image h45-btn'><i class='fa fa-cloud-download'></i> Tải hình này</a></li>";
                            }
                        }
                    }
                    imageGallery.Text += "</ul>";
                }
            }
        }
        public void LoadData(int userRole)
        {
            int id = Request.QueryString["id"].ToInt(0);

            if (id > 0)
            {
                var p = PostController.GetByID(id);
                if (p == null)
                {
                    PJUtils.ShowMessageBoxSwAlertError("Không tìm thấy bài viết " + id, "e", true, "/danh-sach-bai-viet", Page);
                }
                else
                {
                    ViewState["ID"] = id;

                    ltrEdit.Text = "";
                    if (Convert.ToInt32(ViewState["role"]) == 0 || Convert.ToInt32(ViewState["role"]) == 1)
                    {
                        ltrEdit.Text += "<a href=\"/sua-bai-viet?id=" + p.ID + "\" class=\"btn primary-btn fw-btn not-fullwidth\"><i class=\"fa fa-pencil-square-o\" aria-hidden=\"true\"></i> Chỉnh sửa</a>";
                        ltrEdit.Text += "<a href=\"/tao-bai-viet\" class=\"btn primary-btn fw-btn not-fullwidth print-invoice-merged\"><i class=\"fa fa-file-text-o\" aria-hidden=\"true\"></i> Thêm mới</a>";
                    }
                    ltrEdit.Text += "<a href=\"javascript:;\" onclick=\"copyPostInfo(" + p.ID + ")\" class=\"btn primary-btn not-fullwidth print-invoice-merged\"><i class=\"fa fa-files-o\"></i> Copy nội dung</a>";
                    ltrEdit.Text += "<a href=\"javascript:;\" onclick=\"getAllPostImage('" + p.ID + "');\" class=\"btn primary-btn not-fullwidth print-invoice-merged\"><i class=\"fa fa-cloud-download\"></i> Tải tất cả hình ảnh</a>";

                    ltrTitle.Text   = p.Title;
                    ltrContent.Text = p.Content;


                    // thư viện ảnh
                    var image = PostImageController.GetByPostID(id);
                    imageGallery.Text  = "<ul class=\"image-gallery\">";
                    imageGallery.Text += "<li><img src=\"" + p.Image + "\" /><a href='" + p.Image + "' download class='btn download-btn download-image h45-btn'><i class='fa fa-cloud-download'></i> Tải hình này</a></li>";
                    if (image != null)
                    {
                        foreach (var img in image)
                        {
                            if (img.Image != p.Image)
                            {
                                imageGallery.Text += "<li><img src=\"" + img.Image + "\" /><a href='" + img.Image + "' download class='btn download-btn download-image h45-btn'><i class='fa fa-cloud-download'></i> Tải hình này</a></li>";
                            }
                        }
                    }
                    imageGallery.Text += "</ul>";
                }
            }
        }
Beispiel #8
0
        public void LoadData()
        {
            int id = Request.QueryString["id"].ToInt(0);

            if (id > 0)
            {
                var p = PostController.GetByID(id);
                if (p == null)
                {
                    PJUtils.ShowMessageBoxSwAlertError("Không tìm thấy sản phẩm " + id, "e", true, "/sp", Page);
                }
                else
                {
                    ViewState["ID"]     = id;
                    ViewState["cateID"] = p.CategoryID;

                    ltrProductName.Text = p.Title;
                    ltrContent.Text     = p.Content;

                    if (p.Image != null)
                    {
                        PostThumbnail.Text = "<p><img src=\"" + p.Image + "\" /><a href='" + p.Image + "' download class='btn download-btn download-image h45-btn'><i class='fa fa-cloud-download'></i> Tải hình này</a></p>";
                    }

                    var image = PostImageController.GetByPostID(id);

                    if (image != null)
                    {
                        foreach (var img in image)
                        {
                            if (img.Image != p.Image)
                            {
                                imageGallery.Text += "<p><img src=\"" + img.Image + "\" /><a href='" + img.Image + "' download class='btn download-btn download-image h45-btn'><i class='fa fa-cloud-download'></i> Tải hình này</a></p>";
                            }
                        }
                    }

                    ltrCopyProductInfoButton.Text      = "<p><a href=\"javascript:;\" class=\"btn primary-btn copy-btn h45-btn\" onclick=\"copyPost(" + p.ID + ")\"><i class=\"fa fa-files-o\" aria-hidden=\"true\"></i> Copy</a></p>";
                    ltrDownloadProductImageButton.Text = "<a href =\"javascript:;\" class=\"btn primary-btn h45-btn\" onclick=\"getAllPostImage(" + p.ID + ");\"><i class=\"fa fa-cloud-download\" aria-hidden=\"true\"></i> Tải hình</a>";
                }
            }
        }
Beispiel #9
0
        public void LoadData()
        {
            int id = Request.QueryString["id"].ToInt(0);

            if (id > 0)
            {
                var p = PostController.GetByID(id);
                if (p == null)
                {
                    PJUtils.ShowMessageBoxSwAlertError("Không tìm thấy bài viết " + id, "e", true, "/danh-sach-bai-viet", Page);
                }
                else
                {
                    ViewState["ID"]           = id;
                    ViewState["cateID"]       = p.CategoryID;
                    hdfParentID.Value         = p.CategoryID.ToString();
                    ltrBack.Text              = "<a href=\"/xem-bai-viet?id=" + p.ID + "\" class=\"btn primary-btn fw-btn not-fullwidth\">Trở về</a>";
                    txtPostTitle.Text         = p.Title;
                    pContent.Content          = p.Content;
                    ddlCategory.SelectedValue = p.CategoryID.ToString();
                    ddlFeatured.SelectedValue = p.Featured.ToString();

                    if (p.Image != null)
                    {
                        ListPostThumbnail.Value = p.Image;
                        PostThumbnail.ImageUrl  = p.Image;
                    }

                    var image = PostImageController.GetByPostID(id);
                    imageGallery.Text = "<ul class=\"image-gallery\">";
                    if (image != null)
                    {
                        foreach (var img in image)
                        {
                            imageGallery.Text += "<li><img src='" + img.Image + "' /><a href='javascript:;' data-image-id='" + img.ID + "' onclick='deleteImageGallery($(this))' class='btn-delete'><i class=\"fa fa-times\" aria-hidden=\"true\"></i> Xóa hình</a></li>";
                        }
                    }
                    imageGallery.Text += "</ul>";
                }
            }
        }
        public static string deletePost(int id)
        {
            var    post   = PostController.GetByID(id);
            string result = "";

            if (post != null)
            {
                // Delete image gallery
                var postImage = PostImageController.GetByPostID(post.ID);
                if (postImage.Count > 0)
                {
                    foreach (var img in postImage)
                    {
                        if (!string.IsNullOrEmpty(img.Image))
                        {
                            // Delete in database
                            string deletePostImage = PostImageController.Delete(img.ID);
                        }
                    }
                }

                string deletePost = PostController.Delete(id);

                if (!string.IsNullOrEmpty(deletePost))
                {
                    result = "success";
                }
                else
                {
                    result = "failed";
                }
            }
            else
            {
                result = "notfound";
            }

            return(result);
        }
Beispiel #11
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);
                }
            }
        }