📄 cpost.aspx.cs
字号:
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DNNLite.Entites.Modules;
using DNNLite.Service;
using DNNLite.DesktopModules.Comment;
using System.Web.Configuration;
using NHibernate.Expression;
public partial class DesktopModules_Comment_CPost : System.Web.UI.Page
{
private string key = string.Empty;
private string subject = string.Empty;
private bool cancomment;
private bool needcomment;
protected void Page_Load(object sender, EventArgs e)
{
if (!CheckRequest() || !needcomment)
{
Response.End();
}
if (string.IsNullOrEmpty(Request["commentid"]))
{
Response.End();
}
if (needcomment)
{
if (cancomment)
{
#region 添加评论
string user = Request["user"];
string content = Request["content"];
string ip = DNNLite.Util.DnnLiteTools.RemoteIp();
//立场
string side = Request["side"];
if (User.Identity.IsAuthenticated)
{
user = User.Identity.Name;
}
if (string.IsNullOrEmpty(user ))
{
user = "匿名";
}
if ( string.IsNullOrEmpty( content ) )
{
Response.Write("没有评论内容");
Response.End();
}
if (content.Length > 500)
{
Response.Write("评论内容超长了!");
Response.End();
}
CommentSubject sub = CommentSubject.FindFirst(new EqExpression("CommentKey", key));
Comment c = new Comment();
sub.CommentCount += 1;
if (side == "backer")
{
sub.Backers += 1;
c.StandPoint = true;
}
else if (side == "anti")
{
sub.Antis += 1;
c.StandPoint = false;
}
else
{
sub.Neutrals += 1;
c.StandPoint = null;
}
c.Subject = sub;
c.RawCommentContent = content;
c.CommentUser = user;
c.Ip = ip;
c.CreateDate = DateTime.Now;
c.Visible = true;
c.Create();
sub.Update();
Response.Write("评论成功");
#endregion
}
else
{
Response.Write("评论已经结束");
}
}
}
#region 检查request
private bool CheckRequest()
{
int commenttabmoduleid = 0;
int sourcetabmoduleid = 0;
if (!int.TryParse(Request["commenttabmoduleid"], out commenttabmoduleid))
{
return false;
}
if (!int.TryParse(Request["sourcetabmoduleid"], out sourcetabmoduleid))
{
return false;
}
string commentkey = Request["commentkey"];
string check = Request["commentcheck"];
if (string.IsNullOrEmpty(commentkey) || string.IsNullOrEmpty(check))
{
return false;
}
if (!DNNLite.Util.MD5CheckSum.CheckSum(commentkey, check))
{
return false;
}
IDictionary<string, string> Settings =
TabModuleController.GetTabModuleSettings(commenttabmoduleid);
if (commenttabmoduleid != sourcetabmoduleid)
{
int tabmoduleid = sourcetabmoduleid;
TabModule tm = SystemLoadController.GetTabModule(tabmoduleid);
foreach (ModuleControlInfo ctl in tm.ModuleDefiniton.ModuleControls)
{
if (string.IsNullOrEmpty(ctl.ControlKey))
{
PortalModuleBase p =
(PortalModuleBase)LoadControl(ctl.ControlSrc);
if (!(p is ICommentAble)) { return false; }
ICommentAble comment = p as ICommentAble;
CommentOption opt = comment.GetCommentOption(commentkey);
key = opt.CommentKey;
subject = opt.Subject;
cancomment = opt.CanComment;
needcomment = opt.NeedComment;
return true;
}
}
return false;
}
else
{
if (!Settings.ContainsKey("source")) { return false; }
if (Settings["source"] == "module") { return false; }
key = Settings["key"];
subject = Settings["subject"];
cancomment = bool.Parse(Settings["cancomment"]);
needcomment = bool.Parse(Settings["needcomment"]);
return true;
}
}
#endregion
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -