/// <summary> /// Marks the thread as done. /// </summary> /// <param name="threadID">Thread ID.</param> /// <returns></returns> public static bool MarkThreadAsDone(int threadID) { // load the entity from the database ThreadEntity thread = ThreadGuiHelper.GetThread(threadID); if (thread == null) { // not found return(false); } // get the support queue the thread is in (if any) SupportQueueEntity containingSupportQueue = SupportQueueGuiHelper.GetQueueOfThread(threadID); thread.MarkedAsDone = true; // if the thread is in a support queue, the thread has to be removed from that queue. This is a multi-entity action and therefore we've to start a // transaction if that's the case. If not, we can use the easy route and simply save the thread and be done with it. if (containingSupportQueue == null) { // not in a queue, simply save the thread. return(thread.Save()); } // in a queue, so remove from the queue and save the entity. Transaction trans = new Transaction(IsolationLevel.ReadCommitted, "MarkThreadDone"); trans.Add(thread); try { // save the thread bool result = thread.Save(); if (result) { // save succeeded, so remove from queue, pass the current transaction to the method so the action takes place inside this transaction. SupportQueueManager.RemoveThreadFromQueue(threadID, trans); } trans.Commit(); return(true); } catch { // rollback transaction trans.Rollback(); throw; } finally { trans.Dispose(); } }
/// <summary> /// Creates a new message in the given thread and closes the thread right after the addition of the message, /// which makes the just added message the 'close' message of the thread. Close messages are handy when the /// closure of a thread is not obvious. /// Caller should validate input parameters. /// </summary> /// <param name="threadID">Thread wherein the new message will be placed</param> /// <param name="userID">User who posted this message</param> /// <param name="messageText">Message text</param> /// <param name="messageAsHTML">Message text as HTML</param> /// <param name="userIDIPAddress">IP address of user calling this method</param> /// <param name="messageAsXML">Message text as XML, which is the result of the parse action on MessageText.</param> /// <param name="threadUpdatedNotificationTemplate">The thread updated notification template.</param> /// <param name="emailData">The email data.</param> /// <param name="sendReplyNotifications">Flag to signal to send reply notifications. If set to false no notifications are mailed, /// otherwise a notification is mailed to all subscribers to the thread the new message is posted in</param> /// <returns>MessageID if succeeded, 0 if not.</returns> public static int CreateNewMessageInThreadAndCloseThread(int threadID, int userID, string messageText, string messageAsHTML, string userIDIPAddress, string messageAsXML, string threadUpdatedNotificationTemplate, Dictionary <string, string> emailData, bool sendReplyNotifications) { Transaction trans = new Transaction(IsolationLevel.ReadCommitted, "InsertNewMessage"); int messageID = 0; try { DateTime postingDate = DateTime.Now; messageID = InsertNewMessage(threadID, userID, messageText, messageAsHTML, userIDIPAddress, messageAsXML, trans, postingDate); MessageManager.UpdateStatisticsAfterMessageInsert(threadID, userID, trans, postingDate, false, false); ThreadEntity thread = new ThreadEntity(); trans.Add(thread); thread.FetchUsingPK(threadID); thread.IsClosed = true; thread.IsSticky = false; thread.MarkedAsDone = true; bool result = thread.Save(); if (result) { // save succeeded, so remove from queue, pass the current transaction to the method so the action takes place inside this transaction. SupportQueueManager.RemoveThreadFromQueue(threadID, trans); } trans.Commit(); } catch (Exception) { trans.Rollback(); throw; } finally { trans.Dispose(); } if (sendReplyNotifications) { // send notification email to all subscribers. Do this outside the transaction so a failed email send action doesn't terminate the save process // of the message. ThreadManager.SendThreadReplyNotifications(threadID, userID, threadUpdatedNotificationTemplate, emailData); } return(messageID); }