public static Topic Create(int forumId, string title, string body, int memberId) { var topic = new Topic { ParentId = forumId, Title = title, Body = body, MemberId = memberId, LatestReplyAuthor = memberId, Replies = 0 }; topic.Save(); return(topic); }
public void Delete() { DeleteEventArgs e = new DeleteEventArgs(); FireBeforeDelete(e); if (!e.Cancel) { Topic t = Topic.GetTopic(this.TopicId); Forum f = new Forum(t.ParentId); Data.SqlHelper.ExecuteNonQuery("DELETE FROM forumComments WHERE id = " + Id.ToString()); Id = 0; t.Save(true); f.Save(); FireAfterDelete(e); } }
public static Topic Create(int forumId, string title, string body, int memberId) { var topic = new Topic { ParentId = forumId, Title = title, Body = body, MemberId = memberId, LatestReplyAuthor = memberId, Replies = 0 }; topic.Save(); return topic; }
public void Save() { if (Id == 0) { if (Library.Utills.IsMember(MemberId) && !string.IsNullOrEmpty(Body)) { CreateEventArgs e = new CreateEventArgs(); FireBeforeCreate(e); if (!e.Cancel) { Data.SqlHelper.ExecuteNonQuery("INSERT INTO forumComments (topicId, memberId, body, position) VALUES(@topicId, @memberId, @body, @position)", Data.SqlHelper.CreateParameter("@topicId", TopicId), Data.SqlHelper.CreateParameter("@memberId", MemberId), Data.SqlHelper.CreateParameter("@body", Body), Data.SqlHelper.CreateParameter("@position", Position) ); Created = DateTime.Now; Id = Data.SqlHelper.ExecuteScalar<int>("SELECT MAX(id) FROM forumComments WHERE memberId = @memberId", Data.SqlHelper.CreateParameter("@memberId", MemberId)); Topic t = new Topic(TopicId); if (t.Exists) { t.Save(); } Forum f = new Forum(t.ParentId); if (f.Exists) { f.SetLatestComment(Id); f.SetLatestTopic(t.Id); f.SetLatestAuthor(MemberId); f.LatestPostDate = DateTime.Now; f.Save(); } FireAfterCreate(e); } } } else { UpdateEventArgs e = new UpdateEventArgs(); FireBeforeUpdate(e); if (!e.Cancel) { Data.SqlHelper.ExecuteNonQuery("UPDATE forumComments SET topicId = @topicId, memberId = @memberId, body = @body WHERE id = @id", Data.SqlHelper.CreateParameter("@topicId", TopicId), Data.SqlHelper.CreateParameter("@memberId", MemberId), Data.SqlHelper.CreateParameter("@body", Body), Data.SqlHelper.CreateParameter("@id", Id) ); FireAfterUpdate(e); } } }
public void Delete() { DeleteEventArgs e = new DeleteEventArgs(); FireBeforeDelete(e); if (!e.Cancel) { Topic t = new Topic(this.TopicId); Forum f = new Forum(t.ParentId); Data.SqlHelper.ExecuteNonQuery("DELETE FROM forumComments WHERE id = " + Id.ToString()); Id = 0; t.Save(true); f.Save(); FireAfterDelete(e); } }
public static Topic Create(int forumId, string title, string body, int memberId) { Topic t = new Topic(); t.ParentId = forumId; t.Title = title; t.Body = body; t.MemberId = memberId; t.LatestReplyAuthor = memberId; t.Replies = 0; t.Save(); return t; }
public void Save(bool dontMarkAsSpam) { if (Id == 0) { if (Library.Utills.IsMember(MemberId) && !string.IsNullOrEmpty(Body)) { CreateEventArgs e = new CreateEventArgs(); FireBeforeCreate(e); if (e.Cancel) { return; } Data.SqlHelper.ExecuteNonQuery("INSERT INTO forumComments (topicId, memberId, body, position, isSpam) VALUES(@topicId, @memberId, @body, @position, @isSpam)", Data.SqlHelper.CreateParameter("@topicId", TopicId), Data.SqlHelper.CreateParameter("@memberId", MemberId), Data.SqlHelper.CreateParameter("@body", Body), Data.SqlHelper.CreateParameter("@position", Position), Data.SqlHelper.CreateParameter("@isSpam", dontMarkAsSpam ? false : Forum.IsSpam(MemberId, Body, "comment")) ); Created = DateTime.Now; Id = Data.SqlHelper.ExecuteScalar <int>("SELECT MAX(id) FROM forumComments WHERE memberId = @memberId", Data.SqlHelper.CreateParameter("@memberId", MemberId)); Topic t = Topic.GetTopic(TopicId); if (t.Exists) { t.Save(); } Forum f = new Forum(t.ParentId); if (f.Exists) { f.SetLatestComment(Id); f.SetLatestTopic(t.Id); f.SetLatestAuthor(MemberId); f.LatestPostDate = DateTime.Now; f.Save(); } FireAfterCreate(e); } } else { UpdateEventArgs e = new UpdateEventArgs(); FireBeforeUpdate(e); if (!e.Cancel) { Data.SqlHelper.ExecuteNonQuery("UPDATE forumComments SET topicId = @topicId, memberId = @memberId, body = @body, isSpam = @isSpam WHERE id = @id", Data.SqlHelper.CreateParameter("@topicId", TopicId), Data.SqlHelper.CreateParameter("@memberId", MemberId), Data.SqlHelper.CreateParameter("@body", Body), Data.SqlHelper.CreateParameter("@id", Id), Data.SqlHelper.CreateParameter("@isSpam", dontMarkAsSpam ? false : Forum.IsSpam(MemberId, Body, "comment")) ); FireAfterUpdate(e); } } }