/// <summary> /// Create the topic and the relative root message. /// </summary> /// <param name="category"></param> /// <param name="owner"></param> /// <param name="title"></param> /// <param name="body"></param> /// <param name="attachment">Use null if you don't have any attachment</param> /// <param name="topic">Returns the topic created</param> /// <param name="rootMessage">Returns the message created</param> public static void CreateTopic(Category category, string owner, string title, string body, Attachment.FileInfo attachment, out Topic topic, out Message rootMessage) { Provider.CreateTopic(category, owner, title, body, attachment, out topic, out rootMessage); }
public static void DeleteMessage(Message message) { Provider.DeleteMessage(message); }
/// <summary> /// Create the topic and the relative root message. /// </summary> /// <param name="category"></param> /// <param name="owner"></param> /// <param name="title"></param> /// <param name="body"></param> /// <param name="attachment">Use null if you don't have any attachment</param> /// <param name="topic">Returns the topic created</param> /// <param name="rootMessage">Returns the message created</param> public abstract void CreateTopic(Category category, string owner, string title, string body, Attachment.FileInfo attachment, out Topic topic, out Message rootMessage);
public abstract void DeleteMessage(Message message);
public override Message CreateMessage(Topic topic, string idParentMessage, string owner, string title, string body, Attachment.FileInfo attachment) { //Check attachment if (attachment != null) Attachment.FileHelper.CheckFile(attachment, topic.Category.AttachExtensions, topic.Category.AttachMaxSize); using (TransactionScope transaction = new TransactionScope(Configuration)) { TopicDataStore topicStore = new TopicDataStore(transaction); topicStore.Attach(topic); MessageDataStore messageStore = new MessageDataStore(transaction); Message parentMessage = messageStore.FindByKey(idParentMessage); if (parentMessage == null) throw new MessageNotFoundException(idParentMessage); Message newMessage = new Message(topic, idParentMessage, owner, title, body, attachment); messageStore.Insert(newMessage); transaction.Commit(); //Notify user for answer NotifyUserReply(parentMessage, newMessage); return newMessage; } }
/// <summary> /// Send a notification to the user of the parent message /// </summary> /// <param name="parent"></param> /// <param name="message">Answer</param> private void NotifyUserReply(Message parent, Message message) { if (NotificationProvider == null) return; if (parent.Owner == null) return; XHTMLText xhtml = new XHTMLText(); xhtml.Load(message.Body); //Create the parameters list Dictionary<string, string> parameters = new Dictionary<string, string>(); parameters.Add("?title?", message.Title); parameters.Add("?bodyhtml?", message.Body); parameters.Add("?bodytext?", xhtml.GetShortText()); parameters.Add("?user?", message.Owner); parameters.Add("?idmessage?", message.Id); parameters.Add("?idforum?", parent.Topic.Category.Id); parameters.Add("?idtopic?", parent.Topic.Id); parameters.Add("?forum?", parent.Topic.Category.Name); parameters.Add("?forumDisplayName?", parent.Topic.Category.DisplayName); if (parent.Owner != null && parent.Owner.Length > 0) { System.Web.Security.MembershipUser destinationUser = System.Web.Security.Membership.GetUser(parent.Owner); if (destinationUser != null && UserCanReceiveNotification(destinationUser)) //NotificationProvider.UserCanReceiveNotification(destinationUser { NotificationProvider.NotifyUser(destinationUser, parameters); } } }
/// <summary> /// Recursively delete all the messages and the relative attachments /// </summary> protected virtual void InternalDeleteMessage(MessageDataStore store, TransactionScope transaction, Message obj) { //Recursively delete any child message IList<Message> children = store.FindByParent(obj.Id); foreach (Message childMsg in children) InternalDeleteMessage(store, transaction, childMsg); store.Delete(obj.Id); }
public override void DeleteMessage(Message message) { using (TransactionScope transaction = new TransactionScope(Configuration)) { MessageDataStore store = new MessageDataStore(transaction); InternalDeleteMessage(store, transaction, message); transaction.Commit(); } }
/// <summary> /// Create the topic and the relative root message. /// </summary> /// <param name="category"></param> /// <param name="owner"></param> /// <param name="title"></param> /// <param name="body"></param> /// <param name="attachment">Use null if you don't have any attachment</param> /// <param name="topic">Returns the topic created</param> /// <param name="rootMessage">Returns the message created</param> public override void CreateTopic(Category category, string owner, string title, string body, Attachment.FileInfo attachment, out Topic topic, out Message rootMessage) { //Check attachment if (attachment != null) Attachment.FileHelper.CheckFile(attachment, category.AttachExtensions, category.AttachMaxSize); using (TransactionScope transaction = new TransactionScope(Configuration)) { CategoryDataStore forumStore = new CategoryDataStore(transaction); forumStore.Attach(category); //Insert topic TopicDataStore topicStore = new TopicDataStore(transaction); topic = new Topic(category, owner, title); topicStore.Insert(topic); //Insert root message MessageDataStore messageStore = new MessageDataStore(transaction); rootMessage = new Message(topic, null, owner, title, body, attachment); messageStore.Insert(rootMessage); transaction.Commit(); } }