public static PostClone Update(PostClone data) { using (var con = new inventorymanagementEntities()) { var post = con.PostClones.Where(o => o.ID == data.ID).FirstOrDefault(); if (post != null) { post.PostPublicID = data.PostPublicID; post.Web = data.Web; post.PostWebID = data.PostWebID; post.CategoryID = data.CategoryID; post.CategoryName = data.CategoryName; post.Title = data.Title; post.Summary = data.Summary; post.Content = data.Content; post.Thumbnail = data.Thumbnail; post.CreatedBy = data.CreatedBy; post.CreatedDate = data.CreatedDate; post.ModifiedBy = data.ModifiedBy; post.ModifiedDate = data.ModifiedDate; con.SaveChanges(); return(post); } return(null); } }
public static PostClone Insert(PostClone data) { using (var con = new inventorymanagementEntities()) { con.PostClones.Add(data); con.SaveChanges(); return(data); } }
public static PostClone Get(int postPublicID, string web) { using (var dbe = new inventorymanagementEntities()) { PostClone result = dbe.PostClones.Where(p => p.Web == web && p.PostPublicID == postPublicID).FirstOrDefault(); if (result != null) { return(result); } return(null); } }
public static string createClone(string web, int postPublicID) { // Kiểm tra post clone tồn tại chưa var postClone = PostCloneController.Get(postPublicID, web); if (postClone != null) { return("existPostClone"); } // Kiểm tra post public tồn tại không var postPublic = PostPublicController.GetByID(postPublicID); if (postClone != null) { return("notExistPostPublic"); } string categoryName = ""; // Lấy danh mục bài viết if (postPublic.CategoryID != 0) { var category = PostPublicCategoryController.GetByID(postPublic.CategoryID); categoryName = category.Name; } // Tạo post clone var newPostClone = new PostClone() { PostPublicID = postPublicID, Web = web, PostWebID = 0, CategoryID = postPublic.CategoryID, CategoryName = categoryName, Title = postPublic.Title, Content = postPublic.Content, Summary = postPublic.Summary, Thumbnail = postPublic.Thumbnail, CreatedDate = DateTime.Now, CreatedBy = postPublic.CreatedBy, ModifiedBy = postPublic.ModifiedBy }; var createPostClone = PostCloneController.Insert(newPostClone); if (createPostClone != null) { return(JsonConvert.SerializeObject(createPostClone)); } return("null"); }
public static PostClone GetByID(int ID) { using (var dbe = new inventorymanagementEntities()) { PostClone ai = dbe.PostClones.Where(a => a.ID == ID).SingleOrDefault(); if (ai != null) { return(ai); } return(null); } }
public static string Delete(int ID) { using (var dbe = new inventorymanagementEntities()) { PostClone ui = dbe.PostClones.Where(o => o.ID == ID).FirstOrDefault(); if (ui != null) { dbe.PostClones.Remove(ui); int kq = dbe.SaveChanges(); return(kq.ToString()); } else { return(null); } } }
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); } } }
private async Task <Posts> _handleWPPost(PostClone postClone, WPObject wpObject, string domain, string rootFolder) { #region Category List var categories = new List <int>(); var wpPostCategory = await wpObject.Categories.GetAll(new Dictionary <string, string>() { { "per_page", "100" } }); if (wpPostCategory.Count > 0) { int wpPostCategoryID = Convert.ToInt32(wpPostCategory.Where(x => x.name == postClone.CategoryName).Select(x => x.id).FirstOrDefault()); if (wpPostCategoryID > 0) { categories.Add(wpPostCategoryID); } else { Categories newCategory = new Categories() { name = postClone.CategoryName, description = postClone.CategoryName, parent = 0, }; var createCategory = await wpObject.Categories.Add(newCategory); categories.Add(Convert.ToInt32(createCategory.id)); } } #endregion #region Thumbnail int featured_media = 0; Media wpPostThumbnail = new Media(); if (!String.IsNullOrEmpty(postClone.Thumbnail)) { string thumbnailFileName = Path.GetFileName(postClone.Thumbnail); string filePath = rootFolder + postClone.Thumbnail.Replace("/", @"\"); if (System.IO.File.Exists(filePath)) { wpPostThumbnail = await wpObject.Media.Add(thumbnailFileName, filePath); featured_media = (int)wpPostThumbnail.id; } } #endregion #region Content string content = postClone.Content; // Video string videoHTML = ""; var videoList = _service.getVideoByPostID(postClone.PostPublicID); if (videoList.Count > 0) { foreach (var item in videoList) { videoHTML += String.Format("<iframe width='560' height='315' src='https://www.youtube.com/embed/{0}?controls=0' title='{1}' frameborder='0' allow='accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture' allowfullscreen></iframe><br>", item.VideoId, postClone.Title); } content = videoHTML + content; } // Image if (!String.IsNullOrEmpty(wpPostThumbnail.source_url)) { content = String.Format("<p><img src='{0}' alt='{1}' /></p>", wpPostThumbnail.source_url, postClone.Title) + content; } var postImage = _service.getPostImageByPostID(postClone.PostPublicID); if (postImage.Count > 0) { foreach (var item in postImage) { string imageFileName = Path.GetFileName(item.Image); string filePath = rootFolder + item.Image.Replace("/", @"\"); if (System.IO.File.Exists(filePath)) { var wpPostImage = await wpObject.Media.Add(imageFileName, filePath); content += String.Format("<p><img src='/wp-content/uploads/{0}' alt='{1}' /></p>", System.IO.Path.GetFileName(wpPostImage.source_url), postClone.Title); } } } #endregion return(new Posts() { title = postClone.Title, content = content, excerpt = postClone.Summary, featured_media = featured_media, categories = categories, status = "publish" }); }