📄 deletepost.cs
字号:
//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
// Copyright (c) Telligent Systems Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
// TODO: Add logic to ensure only users in the Forum-Moderators group have access
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using CommunityServer.Components;
using CommunityServer.Controls;
using CommunityServer.Discussions.Components;
namespace CommunityServer.Discussions.Controls
{
// *********************************************************************
// DeletePost
//
/// <summary>
/// This control is used by forum moderators to delete posts
/// </summary>
// ***********************************************************************/
public class DeletePost : SkinnedWebControl
{
#region Member variables and constructor
CSContext csContext = CSContext.Current;
string skinFilename = "DeletePost.ascx";
RequiredFieldValidator ValidateReason;
TextBox reasonForDelete;
Label hasReplies;
ForumPost postToDelete;
Button deleteButton;
Button cancelButton;
// *********************************************************************
// DeletePost
//
/// <summary>
/// Constuctor
/// </summary>
// ***********************************************************************/
public DeletePost() : base()
{
// Assign a default template name
if (SkinFilename == null)
SkinFilename = skinFilename;
if (csContext.ReturnUrl == null)
{
throw new CSException(CSExceptionType.ReturnURLRequired);
}
}
#endregion
#region Rendering
// *********************************************************************
// Initializeskin
//
/// <summary>
/// Initialize the control template and populate the control with values
/// </summary>
// ***********************************************************************/
override protected void InitializeSkin(Control skin)
{
// Get the post we are deleting
postToDelete = Posts.GetPost(csContext.PostID, csContext.User.UserID);
// Check if the user has permission to delete the post
//
Permissions.AccessCheck(postToDelete.Section, Permission.Delete, CSContext.Current.User, postToDelete);
// Text box containing the reason why the post was deleted. This note will be
// sent to the end user.
reasonForDelete = (TextBox) skin.FindControl("DeleteReason");
// Display the post being deleted
//
((Label) skin.FindControl("PreviewSubject")).Text = string.Format(ResourceManager.GetString("DeletePost_Title"), postToDelete.Subject);
((Label) skin.FindControl("PreviewBody")).Text = postToDelete.FormattedBody;
// Who is deleting the post
//
((Label) skin.FindControl("DeletedBy")).Text = CSContext.Current.User.Username;
// Does the post have any replies?
hasReplies = (Label) skin.FindControl("HasReplies");
if (null != hasReplies)
{
// check to see if the Moderator is deleting childposts
//
if (csContext.QueryText == "childposts")
{
if (postToDelete.Replies > 0)
hasReplies.Text = ResourceManager.GetString("Yes") + " (" + postToDelete.Replies.ToString() + ") ";
else
hasReplies.Text = ResourceManager.GetString("No");
}
else
hasReplies.Text = ResourceManager.GetString("DeletePost_NA");
}
// Perform the delete
deleteButton = (Button) skin.FindControl("DeletePost");
if (null != deleteButton)
{
deleteButton.Click += new System.EventHandler(DeletePost_Click);
deleteButton.Attributes["onclick"] = "return confirm('" + ResourceManager.GetString("DeletePost_PopupConfirmation").Replace("'", @"\'") + "');";
deleteButton.Text = ResourceManager.GetString("DeletePost_DeletePost");
}
// Cancel the delete
cancelButton = (Button) skin.FindControl("CancelDelete");
if (null != cancelButton)
{
cancelButton.Click += new EventHandler(CancelDelete_Click);
cancelButton.Text = ResourceManager.GetString("DeletePost_CancelDelete");
}
// Validator for reason to delete
ValidateReason = (RequiredFieldValidator) skin.FindControl("ValidateReason");
ValidateReason.ErrorMessage = ResourceManager.GetString("DeletePost_ValidateReason");
}
#endregion
#region Events
// *********************************************************************
// DeletePost_Click
//
/// <summary>
/// Event handler for deleting a post
/// </summary>
// ***********************************************************************/
private void DeletePost_Click(Object sender, EventArgs e)
{
// Are we valid?
if (ValidateReason.IsValid)
{
// Get the post we are going to delete
//
ForumPost post = (ForumPost) Posts.GetPost(csContext.PostID, CSContext.Current.User.UserID);
// get the old ForumID to redirect to, before we delete it and
// loose this information.
//
int oldForumID = post.SectionID;
// Perform the delete
//
if (csContext.QueryText == "childposts")
Moderate.DeletePost(post, CSContext.Current.User, reasonForDelete.Text, true);
else
Moderate.DeletePost(post, CSContext.Current.User, reasonForDelete.Text, false);
// Did we delete a thread?
//
if (csContext.ReturnUrl != String.Empty)
{
csContext.Context.Response.Redirect(csContext.ReturnUrl, true);
}
else
{
csContext.Context.Response.Redirect(ForumUrls.Instance().Forum(oldForumID), true);
}
}
}
// *********************************************************************
// CancelDelete_Click
//
/// <summary>
/// Event handler for canceling deletion of a post
/// </summary>
// ***********************************************************************/
private void CancelDelete_Click(Object sender, EventArgs e)
{
csContext.Context.Response.Clear();
csContext.Context.Response.Redirect(csContext.ReturnUrl, true);
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -