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 = PostPublicController.GetByID(id); string result = ""; if (post != null) { // Delete image gallery var postImage = PostPublicImageController.GetByPostID(post.ID); if (postImage.Count > 0) { foreach (var img in postImage) { if (!string.IsNullOrEmpty(img.Image)) { // Delete in database string deletePostImage = PostPublicImageController.Delete(img.ID); } } } string deletePost = PostPublicController.Delete(id); if (!string.IsNullOrEmpty(deletePost)) { result = "success"; } else { result = "failed"; } // Delete clone var postClone = PostCloneController.GetAll(id); if (postClone.Count > 0) { foreach (var item in postClone) { PostCloneController.Delete(item.ID); } } } else { result = "notfound"; } return(result); }
public void LoadData() { int id = Request.QueryString["id"].ToInt(0); if (id > 0) { var p = PostPublicController.GetByID(id); if (p == null) { PJUtils.ShowMessageBoxSwAlertError("Không tìm thấy bài viết " + id, "e", true, "/danh-sach-bai-viet-app", Page); } else { this.Title = String.Format("{0} - Sửa bài viết App", p.Title.ToTitleCase()); ViewState["ID"] = id; ViewState["cateID"] = p.CategoryID; hdfParentID.Value = p.CategoryID.ToString(); ltrBack.Text = "<a href='/xem-bai-viet-app?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; if (p.Action == "show_web") { txtLink.Text = p.ActionValue; } else if (p.Action == "view_more") { txtSlug.Text = p.ActionValue; } ddlCategory.SelectedValue = p.CategoryID.ToString(); ddlAction.SelectedValue = p.Action.ToString(); hdfAction.Value = p.Action.ToString(); ddlAtHome.SelectedValue = p.AtHome.ToString(); ddlIsPolicy.SelectedValue = p.IsPolicy.ToString(); pSummary.Content = p.Summary; pContent.Content = p.Content; if (p.Thumbnail != null) { ListPostPublicThumbnail.Value = p.Thumbnail; PostPublicThumbnail.ImageUrl = p.Thumbnail; } var image = PostPublicImageController.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; hdfPostVariants.Value = PostCloneController.getFeesJSON(id); } } }
protected void btnSubmit_Click(object sender, EventArgs e) { string username = Request.Cookies["usernameLoginSystem"].Value; var acc = AccountController.GetByUsername(username); DateTime currentDate = DateTime.Now; int PostID = ViewState["ID"].ToString().ToInt(0); var post = PostPublicController.GetByID(PostID); if (post != null) { int CategoryID = hdfParentID.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 = ddlIsPolicy.SelectedValue.ToBool(); //Phần thêm ảnh đại diện sản phẩm string path = "/uploads/images/posts/"; string Thumbnail = ListPostPublicThumbnail.Value; if (PostPublicThumbnailImage.UploadedFiles.Count > 0) { foreach (UploadedFile f in PostPublicThumbnailImage.UploadedFiles) { var o = path + "post-app-" + PostID + '-' + Slug.ConvertToSlug(Path.GetFileName(f.FileName), isFile: true); try { f.SaveAs(Server.MapPath(o)); Thumbnail = 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 = PostPublicImageController.GetByID(Convert.ToInt32(deletelist[i])); if (img != null) { string delete = PostPublicImageController.Delete(img.ID); } } } // Update post var oldPostPublic = new PostPublic() { ID = PostID, CategoryID = CategoryID, CategorySlug = CategorySlug, Title = Title, Thumbnail = Thumbnail, Summary = Summary, Content = Content, Action = Action, ActionValue = ActionValue, AtHome = AtHome, IsPolicy = IsPolicy, CreatedDate = post.CreatedDate, CreatedBy = acc.Username, ModifiedDate = currentDate, ModifiedBy = acc.Username }; var updatePost = PostPublicController.Update(oldPostPublic); if (updatePost != null) { // Cập nhật thư viện ảnh cho bài viết if (UploadImages.HasFiles) { foreach (HttpPostedFile uploadedFile in UploadImages.PostedFiles) { var o = path + "post-app-" + PostID + '-' + Slug.ConvertToSlug(Path.GetFileName(uploadedFile.FileName), isFile: true); uploadedFile.SaveAs(Server.MapPath(o)); PostPublicImageController.Insert(PostID, o, username, 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 getpostClone = PostCloneController.Get(updatePost.ID, item.Web); if (getpostClone == null) { continue; } var oldPostClone = new PostClone() { ID = getpostClone.ID, PostPublicID = updatePost.ID, Web = getpostClone.Web, PostWebID = getpostClone.PostWebID, CategoryName = category.Name, CategoryID = updatePost.CategoryID, Title = !String.IsNullOrEmpty(item.Title) ? item.Title : updatePost.Title, Summary = updatePost.Summary, Content = updatePost.Content, Thumbnail = updatePost.Thumbnail, CreatedBy = getpostClone.CreatedBy, CreatedDate = getpostClone.CreatedDate, ModifiedDate = currentDate, ModifiedBy = acc.Username }; PostCloneController.Update(oldPostClone); } } } PJUtils.ShowMessageBoxSwAlertCallFunction("Cập nhật bài viết thành công", "s", true, "redirectTo(" + updatePost.ID.ToString() + ")", Page); } } }
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); } } }
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 = PostPublicController.GetByID(id); if (p == null) { PJUtils.ShowMessageBoxSwAlertError("Không tìm thấy bài viết " + id, "e", true, "/danh-sach-bai-viet-app", Page); } else { ltrThumbnail.Text = "<img src='" + p.Thumbnail + "'><a href='" + p.Thumbnail + "' download class='btn download-btn download-image h45-btn'><i class='fa fa-cloud-download'></i> Tải hình này</a>"; ltrSummary.Text = p.Summary; if (p.Action == "show_web") { ltrLink.Text = "<p><strong>Link:</strong> <a href='" + p.ActionValue + "' target='_blank'>" + p.ActionValue + "</a></p>"; } else { ltrContent.Text = p.Content; } this.Title = String.Format("{0} - Bài viết App", p.Title.ToTitleCase()); ltrEditTop.Text = ""; if (acc.RoleID == 0 || acc.Username == "nhom_zalo502") { ltrEditTop.Text += "<a href='/sua-bai-viet-app?id=" + p.ID + "' class='btn primary-btn fw-btn not-fullwidth'><i class='fa fa-pencil-square-o' aria-hidden='true'></i> Sửa</a>"; ltrEditTop.Text += "<a href='/tao-bai-viet-app' class='btn primary-btn fw-btn not-fullwidth print-invoice-merged'><i class='fa fa-file-text-o' aria-hidden='true'></i> Thêm</a>"; ltrEditTop.Text += "<a href='javascript:;' onclick='showPostSyncModal(" + p.ID + ");' class='btn primary-btn fw-btn not-fullwidth print-invoice-merged'><i class='fa fa-refresh' aria-hidden='true'></i> Đồng bộ</a>"; } ltrEditBottom.Text = ltrEditTop.Text; ltrTitle.Text = p.Title; // thư viện ảnh var image = PostPublicImageController.GetByPostID(id); if (image != null) { imageGallery.Text = "<ul class='image-gallery'>"; foreach (var img in image) { if (img.Image != p.Thumbnail) { 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>"; } string Action = ""; if (p.Action == "show_web") { Action = "Link ngoài"; } else { Action = "Bài nội bộ"; } string PostInfo = "<p><strong>Kiểu bài viết</strong>: " + Action + "</p>"; 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; } } }