public static string deletePost(int id) { var post = NotifyController.GetByID(id); string result = ""; if (post != null) { string deletePost = NotifyController.Delete(id); if (!string.IsNullOrEmpty(deletePost)) { result = "success"; } else { result = "failed"; } } else { result = "notfound"; } return(result); }
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 = NotifyController.GetByID(id); if (p == null) { PJUtils.ShowMessageBoxSwAlertError("Không tìm thấy bài viết " + id, "e", true, "/danh-sach-thong-bao", Page); } else { ltrThumbnail.Text = "<img src='" + p.Thumbnail + "'>"; 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} - Thông báo", p.Title.ToTitleCase()); ltrEditTop.Text = ""; if (acc.RoleID == 0 || acc.Username == "nhom_zalo502") { ltrEditTop.Text += "<a href='/sua-thong-bao?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='/tao-thong-bao' 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>"; } ltrEditBottom.Text = ltrEditTop.Text; ltrTitle.Text = p.Title; 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; } } }
public void LoadData() { int id = Request.QueryString["id"].ToInt(0); if (id > 0) { var p = NotifyController.GetByID(id); if (p == null) { PJUtils.ShowMessageBoxSwAlertError("Không tìm thấy bài viết " + id, "e", true, "/danh-sach-thong-bao", Page); } else { this.Title = String.Format("{0} - Sửa thông báo", p.Title.ToTitleCase()); ViewState["ID"] = id; ViewState["cateID"] = p.CategoryID; hdfParentID.Value = p.CategoryID.ToString(); ltrBack.Text = "<a href='/xem-thong-bao?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(); pSummary.Content = p.Summary; pContent.Content = p.Content; if (p.Thumbnail != null) { ListPostPublicThumbnail.Value = p.Thumbnail; PostPublicThumbnail.ImageUrl = p.Thumbnail; } 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; } } }
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 = NotifyController.GetByID(PostID); if (post != null) { int CategoryID = hdfParentID.Value.ToInt(); var category = NotifyCategoryController.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(); //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 + "notify-" + PostID + '-' + Slug.ConvertToSlug(Path.GetFileName(f.FileName), isFile: true); try { f.SaveAs(Server.MapPath(o)); Thumbnail = o; } catch { } } } if (Thumbnail != ListPostPublicThumbnail.Value) { if (File.Exists(Server.MapPath(ListPostPublicThumbnail.Value))) { File.Delete(Server.MapPath(ListPostPublicThumbnail.Value)); } } // Update post var oldNotify = new NotifyNew() { ID = PostID, CategoryID = CategoryID, CategorySlug = CategorySlug, Title = Title, Thumbnail = Thumbnail, Summary = Summary, Content = Content, Action = Action, ActionValue = ActionValue, AtHome = AtHome, CreatedDate = post.CreatedDate, CreatedBy = acc.Username, ModifiedDate = currentDate, ModifiedBy = acc.Username }; var updatePost = NotifyController.Update(oldNotify); if (updatePost != null) { PJUtils.ShowMessageBoxSwAlertCallFunction("Cập nhật bài viết thành công", "s", true, "redirectTo(" + updatePost.ID.ToString() + ")", Page); } } }