📄 itemmoderate.cs
字号:
namespace ASPNET.StarterKit.Communities {
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Diagnostics;
using ASPNET.StarterKit.Communities.Moderation;
using System.Collections;
//*********************************************************************
//
// ItemModerate Class
//
// Enables moderation of a particular content item
//
//*********************************************************************
public class ItemModeration : WebControl, IPostBackEventHandler {
public event ModeratedEventHandler Moderated;
private SectionInfo objSectionInfo;
private UserInfo objUserInfo;
private string _approveText = "Approve";
private string _approveCommentText = "Approve and Comment";
private string _moveText = "Move";
private string _deleteText = "Delete";
//*********************************************************************
//
// ContentPageID Property
//
// The ContentPageID of the content being moderated.
//
//*********************************************************************
public int ContentPageID {
get {return (int)ViewState["ContentPageID"];}
set {ViewState["ContentPageID"] = value; }
}
//*********************************************************************
//
// ReturnUrlHelper Property
//
// Helper method for passing a return URL back to current page.
//
//*********************************************************************
public string ReturnUrlHelper {
get { return Context.Server.UrlEncode("Moderation_ModerateSection.aspx"); }
}
//*********************************************************************
//
// ApproveText Property
//
// The text used for approving content.
//
//*********************************************************************
public string ApproveText {
get { return _approveText; }
set { _approveText = value; }
}
//*********************************************************************
//
// ApproveCommentText Property
//
// The text used for approving and commenting.
//
//*********************************************************************
public string ApproveCommentText {
get { return _approveCommentText; }
set { _approveCommentText = value; }
}
//*********************************************************************
//
// MoveText Property
//
// The text used for moving content.
//
//*********************************************************************
public string MoveText {
get { return _moveText; }
set { _moveText = value; }
}
//*********************************************************************
//
// DeleteText Property
//
// The text used for deleting content.
//
//*********************************************************************
public string DeleteText {
get { return _deleteText; }
set { _deleteText = value; }
}
//*********************************************************************
//
// ItemModeration Constructor
//
// Assign a default css style (the user can override)
//
//*********************************************************************
public ItemModeration() {
CssClass = "itemModeration";
// Get UserInfo
objUserInfo = (UserInfo)Context.Items["UserInfo"];
// Get SectionInfo
objSectionInfo = (SectionInfo)Context.Items["SectionInfo"];
}
//*********************************************************************
//
// OnDataBinding Method
//
// Get the title from the container's DataItem property
//
//*********************************************************************
override protected void OnDataBinding(EventArgs e) {
ContentItem item;
if (NamingContainer is ContentItem)
item = (ContentItem)NamingContainer;
else
item = (ContentItem)NamingContainer.NamingContainer;
ContentInfo objContentInfo = (ContentInfo)item.DataItem;
ContentPageID = objContentInfo.ContentPageID;
}
public virtual void OnModerated(ModeratedEventArgs e) {
// Perform moderation
// Get ContentPageInfo from DataItem
ContentInfo contentInfo = ModerationUtility.GetContentInfo(ContentPageID);;
switch (e.CommandName) {
case "Approve":
ModerationUtility.ApproveContent(objUserInfo.Username, ContentPageID);
// Send Notifications
Context.Server.ScriptTimeout = 10 * 60;
Context.Response.Redirect(CommunityGlobals.CalculatePath("Moderation_ModerateSection.aspx"), false);
Context.Response.Flush();
Context.Response.Close();
NotifyUtility.SendNotifications(objSectionInfo.ID, contentInfo.ContentPageID, contentInfo.Title, contentInfo.Author);
Context.Response.End();
break;
case "ApproveComment":
Context.Server.ScriptTimeout = 10 * 60;
ModerationUtility.ApproveContent(objUserInfo.Username, ContentPageID);
// Send Notifications
Context.Response.Redirect(CommunityGlobals.CalculatePath(String.Format("Comments_AddComment.aspx?id={0}&ReturnUrl={1}", ContentPageID, ReturnUrlHelper)), false);
Context.Response.Flush();
Context.Response.Close();
NotifyUtility.SendNotifications(objSectionInfo.ID, contentInfo.ContentPageID, contentInfo.Title, contentInfo.Author);
Context.Response.End();
break;
}
// if anyone is listening, throw the event
if (Moderated != null)
Moderated(this, e);
}
public void RaisePostBackEvent(string eventArgument) {
OnModerated(new ModeratedEventArgs(eventArgument, ContentPageID));
}
private string LinkHelper(string action, string actionDescription) {
return String.Format("<a id=\"{0}\" href=\"javascript:"+ Page.GetPostBackEventReference(this, action)+ "\">{1}</a>", UniqueID, actionDescription);
}
private string MoveHelper {
get {
string link = String.Format("ContentPages_MoveContentPage.aspx?id={0}&ReturnUrl={1}", ContentPageID, ReturnUrlHelper );
return String.Format("<a href=\"{0}\">{1}</a>", CommunityGlobals.CalculatePath(link), _moveText);
}
}
private string DeleteHelper {
get {
string link = String.Format("ContentPages_DeleteContentPage.aspx?id={0}&ReturnUrl={1}", ContentPageID, ReturnUrlHelper );
return String.Format("<a href=\"{0}\">{1}</a>", CommunityGlobals.CalculatePath(link), _deleteText);
}
}
//*********************************************************************
//
// Render Method
//
// Renders different moderation options.
//
//*********************************************************************
protected override void Render(HtmlTextWriter tw) {
ArrayList colLinks = new ArrayList();
// Add Approve Link
colLinks.Add(LinkHelper( "Approve", _approveText ) );
// Add Approve and Comment Link
if (objUserInfo.MayComment && objSectionInfo.EnableComments)
colLinks.Add(LinkHelper( "ApproveComment", _approveCommentText ) );
// Add Move Link
colLinks.Add( MoveHelper );
// Add Delete Link
if (objUserInfo.MayDelete)
colLinks.Add( DeleteHelper );
tw.RenderBeginTag(HtmlTextWriterTag.Table);
tw.RenderBeginTag(HtmlTextWriterTag.Tr);
int linkCount = colLinks.Count;
int counter = 0;
foreach (string link in colLinks) {
counter ++;
tw.RenderBeginTag(HtmlTextWriterTag.Td);
tw.Write(link);
tw.RenderEndTag(); // close td
// Render Separator
if (counter < linkCount) {
tw.RenderBeginTag(HtmlTextWriterTag.Td);
tw.Write("|");
tw.RenderEndTag(); // close td
}
}
tw.RenderEndTag(); // close tr
tw.RenderEndTag(); // close table
}
}
public delegate void ModeratedEventHandler(Object s, ModeratedEventArgs e);
public class ModeratedEventArgs {
string _commandName;
int _contentPageID;
public string CommandName {
get { return _commandName; }
}
public int ContentPageID {
get { return _contentPageID; }
}
public ModeratedEventArgs(string commandName, int contentPageID) {
_commandName = commandName;
_contentPageID = contentPageID;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -