public int Add(ReplyInfo reply) { string insert = "INSERT INTO " + Config.ForumTablePrefix + "REPLY (CAT_ID,FORUM_ID,TOPIC_ID,R_AUTHOR,R_MESSAGE,R_DATE,R_IP,R_STATUS,R_SIG)"; string values = String.Format("VALUES({0},{1},{2},{3},@Message,'{4}','{5}',{6},{7}); SELECT SCOPE_IDENTITY();" , reply.CatId, reply.ForumId, reply.TopicId, reply.AuthorId, reply.Date.ToString("yyyyMMddHHmmss"), reply.PosterIp,reply.Status, reply.UseSignatures ? 1 : 0); SqlParameter msg = new SqlParameter("@Message", SqlDbType.NVarChar) {Value = reply.Message}; int res = Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.ConnString, CommandType.Text, insert + values, msg)); reply.Id = res; new Topic().UpdateLastTopicPost(reply); new Forum().UpdateLastForumPost(reply); new Member().UpdateLastMemberPost(reply); return reply.Id; }
private static void SendSubscriptions(Enumerators.Subscription subType, TopicInfo topic, ReplyInfo reply,HttpContext context) { int replyid = -1; int authorid = topic.AuthorId; int[] memberids = { }; StringBuilder Message = new StringBuilder("<html><body>Hello {0}"); string strSubject = String.Empty; HttpContext.Current = context; if (reply != null) { replyid = reply.Id; authorid = reply.AuthorId; } Message.Append("<br/><p>"); ISubscription dal = Factory<ISubscription>.Create("Subscription"); switch (subType) { case Enumerators.Subscription.ForumSubscription: memberids = dal.GetForumSubscriptionList(topic.ForumId); if (memberids.Length > 0) { strSubject = Config.ForumTitle.Replace("™", "").Replace("©", "") + " - New posting"; Message.AppendFormat( "{0} has posted to the forum {1} at {2} that you requested notification on.", topic.AuthorName, topic.Forum.Subject, Config.ForumTitle); } break; case Enumerators.Subscription.TopicSubscription: memberids = dal.GetTopicSubscriptionList(topic.Id); if (memberids.Length > 0) { strSubject = Config.ForumTitle.Replace("™", "").Replace("©", "") + " - Reply to a posting"; Message.AppendFormat("{0} has replied to a topic on <b>{1}</b> that you requested notification to.", reply.AuthorName, Config.ForumTitle); } break; } Message.AppendFormat(" Regarding the subject - {0}.", topic.Subject); Message.Append("<br/>"); Message.Append("<br/>"); Message.AppendFormat("You can view the posting <a href=\"{0}Content/Forums/topic.aspx?whichpage=-1&TOPIC={1}", Config.ForumUrl, topic.Id); if (replyid > 0) Message.AppendFormat("#{0}", replyid); Message.Append("\">here</a>"); Message.Append("</p></body></html>"); foreach (int id in memberids) { MemberInfo member = Members.GetMember(id); //don't send the author notification of their own posts if (id == authorid) continue; SnitzEmail email = new SnitzEmail { subject = strSubject, msgBody = String.Format(Message.ToString(), member.Username), toUser = new MailAddress(member.Email, member.Username), IsHtml = true, FromUser = "******" }; email.Send(); } }
public static ReplyInfo CopyReplyToBO(SqlDataReader rdr) { ReplyInfo reply = new ReplyInfo { Id = rdr.GetInt32(0), CatId = rdr.GetInt32(1), ForumId = rdr.GetInt32(2), TopicId = rdr.GetInt32(3), AuthorId = rdr.GetInt32(4), Date = rdr.GetString(5).ToDateTime().Value, PosterIp = rdr.SafeGetString(6), Status = rdr.GetInt16(7), LastEditDate = rdr.SafeGetString(8).ToDateTime(), LastEditedById = rdr.SafeGetInt32(9), UseSignatures = rdr.GetInt16(10) == 1, Message = rdr.SafeGetString(11) }; if (rdr.FieldCount > 12) { reply.AuthorName = rdr.SafeGetString(12); reply.EditorName = rdr.SafeGetString(13); reply.AuthorViewSig = rdr.GetInt16(14) == 1; reply.AuthorSignature = rdr.SafeGetString(15); } return reply; }
private int PostNewReply() { string ipaddress = Common.GetIP4Address(); var poll = new Regex(@"(?<poll>\[poll=(?<question>.+?)](?<answers>.+?)\[\/poll])", RegexOptions.Singleline); if (poll.IsMatch(Message.Text)) { //Polls not allowed in replies Message.Text = poll.Replace(Message.Text, ""); } var reply = new ReplyInfo { Message = Message.Text, PosterIp = ipaddress, Status = (int)Enumerators.PostStatus.Open, UseSignatures = cbxSig.Checked, AuthorId = Member.Id, Date = DateTime.UtcNow }; if (!_inModeratedList) { if (_thisTopic.Forum.ModerationLevel == (int)Enumerators.Moderation.AllPosts || _thisTopic.Forum.ModerationLevel == (int)Enumerators.Moderation.Replies ) { reply.Status = (int)Enumerators.PostStatus.UnModerated; _thisTopic.UnModeratedReplies += 1; } } reply.TopicId = _thisTopic.Id; reply.CatId = _thisTopic.CatId; reply.ForumId = _thisTopic.ForumId; reply.Id = Replies.AddReply(reply); if (cbxLock.Checked && _inModeratedList) _thisTopic.Status = (int)Enumerators.PostStatus.Closed; Topics.Update(_thisTopic); if (pingSiteMap) { Ping(""); } InvalidateForumCache(); return reply.Id; }
public static void UpdateLastTopicPost(ReplyInfo reply) { ITopic dal = Factory<ITopic>.Create("Topic"); dal.UpdateLastTopicPost(reply); }
public static int AddReply(ReplyInfo reply) { IReply dal = Factory<IReply>.Create("Reply"); int replyid = dal.Add(reply); return replyid; }
public void UpdateLastTopicPost(ReplyInfo reply) { string updateTopicSql = "UPDATE " + Config.ForumTablePrefix + "TOPICS SET T_REPLIES=T_REPLIES+1, T_LAST_POST_REPLY_ID=@ReplyId, T_LAST_POST=@ReplyDate, T_LAST_POST_AUTHOR=@ReplyAuthor WHERE TOPIC_ID=@TopicId "; List<OleDbParameter> parms = new List<OleDbParameter> { new OleDbParameter("@ReplyId", OleDbType.Integer) {Value = reply.Id}, new OleDbParameter("@ReplyDate", OleDbType.VarChar) {Value = reply.Date.ToString("yyyyMMddHHmmss")}, new OleDbParameter("@ReplyAuthor", OleDbType.Integer) {Value = reply.AuthorId}, new OleDbParameter("@TopicId", OleDbType.Integer) {Value = reply.TopicId} }; SqlHelper.ExecuteNonQuery(SqlHelper.ConnString, CommandType.Text, updateTopicSql, parms.ToArray()); }
public void Delete(ReplyInfo reply) { string deleteSql = "DELETE FROM " + Config.ForumTablePrefix + "REPLY WHERE REPLY_ID=@ReplyId;"; SqlHelper.ExecuteNonQuery(SqlHelper.ConnString, CommandType.Text, deleteSql, new SqlParameter("@ReplyId", SqlDbType.Int) { Value = reply.Id }); }
public void Update(ReplyInfo reply) { List<SqlParameter> parms = new List<SqlParameter>(); StringBuilder replySql = new StringBuilder(); replySql.AppendFormat("UPDATE {0}REPLY SET",Config.ForumTablePrefix).AppendLine(); replySql.AppendLine("R_MESSAGE=@Message,"); if (reply.LastEditedById.HasValue) { replySql.AppendLine("R_LAST_EDIT=@EditDate,"); replySql.AppendLine("R_LAST_EDITBY=@EditedBy,"); parms.Add(new SqlParameter("@EditDate",SqlDbType.VarChar){Value = DateTime.UtcNow.ToString("yyyyMMddHHmmss")}); parms.Add(new SqlParameter("@EditedBy",SqlDbType.Int){Value = reply.LastEditedById}); } replySql.AppendLine("R_SIG=@UseSig "); replySql.AppendLine("WHERE REPLY_ID=@ReplyId"); parms.Add(new SqlParameter("@Message", SqlDbType.NVarChar) { Value = reply.Message }); parms.Add(new SqlParameter("@UseSig", SqlDbType.Int) { Value = reply.UseSignatures }); parms.Add(new SqlParameter("@ReplyId", SqlDbType.Int) { Value = reply.Id }); SqlHelper.ExecuteNonQuery(SqlHelper.ConnString, CommandType.Text, replySql.ToString(), parms.ToArray()); }
protected void btnSubmit_Click(object sender, EventArgs e) { DateTime newdate = DateTime.UtcNow; if (Session["LastPostMade"] != null) { if ((Config.FloodCheck)&& !(page.IsAdministrator || page.IsModerator)) { TimeSpan diff1 = new TimeSpan(0, 0, 0, Config.FloodTimeout); DateTime dt = newdate - diff1; DateTime? lastpost = Session["LastPostMade"].ToString().ToDateTime(); if (lastpost > dt) throw new HttpException(403, "FloodCheck"); //Response.Redirect("error.aspx?msg=errFloodError"); } } else { Session.Add("LastPostMade", DateTime.UtcNow.ToForumDateStr()); } string MemberIP = Common.GetIP4Address(); ReplyInfo reply = new ReplyInfo { TopicId = thisTopic.Id, ForumId = thisTopic.ForumId, CatId = thisTopic.CatId, UseSignatures = cbxSig.Checked, Message = qrMessage.Text, PosterIp = MemberIP, Status = thisTopic.Status, AuthorId = page.Member.Id, Date = newdate }; var forum = Forums.GetForum(thisTopic.ForumId); if(!(page.IsAdministrator || page.IsModerator)) { if (forum.ModerationLevel == (int) Enumerators.Moderation.AllPosts || forum.ModerationLevel == (int) Enumerators.Moderation.Replies) { reply.Status = (int) Enumerators.PostStatus.UnModerated; thisTopic.UnModeratedReplies += 1; Topics.Update(thisTopic); } } int replyid = Replies.AddReply(reply); if (forum.AllowSubscriptions) { var ws = new CommonFunc(); ws.ProcessForumSubscriptions(reply.TopicId, HttpContext.Current); } if (thisTopic.AllowSubscriptions) { var ws = new CommonFunc(); ws.ProcessTopicSubscriptions(reply.TopicId, replyid, HttpContext.Current); } if (Session["LastPostMade"] == null) { Session.Add("LastPostMade", newdate.ToForumDateStr()); } else { Session["LastPostMade"] = newdate.ToForumDateStr(); } InvalidateForumCache(); Page.Response.Redirect(string.Format("/Content/Forums/topic.aspx?whichpage=-1&TOPIC_ID={0}&#{1}", thisTopic.Id, replyid)); }