Пример #1
0
        /// <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();
            }
        }
Пример #2
0
        /// <summary>
        /// Updates the memo field for the given thread
        /// </summary>
        /// <param name="threadID">Thread ID.</param>
        /// <param name="memo">Memo.</param>
        /// <returns></returns>
        public static bool UpdateMemo(int threadID, string memo)
        {
            // load the entity from the database
            ThreadEntity thread = ThreadGuiHelper.GetThread(threadID);

            if (thread == null)
            {
                // not found
                return(false);
            }

            thread.Memo = memo;

            //update the entity in the database
            return(thread.Save());
        }
Пример #3
0
        /// <summary>
        /// Moves the given thread to the given forum.
        /// </summary>
        /// <param name="threadID">ID of thread to move</param>
        /// <param name="newForumID">ID of forum to move the thread to</param>
        /// <returns></returns>
        public static bool MoveThread(int threadID, int newForumID)
        {
            // load the entity from the database
            ThreadEntity thread = ThreadGuiHelper.GetThread(threadID);

            if (thread == null)
            {
                // not found
                return(false);
            }

            // update the ForumID field with the new value
            thread.ForumID = newForumID;

            // save the updated entity back to the database
            return(thread.Save());
        }
Пример #4
0
        /// <summary>
        /// Modifies the given properties of the given thread.
        /// </summary>
        /// <param name="threadID">The threadID of the thread which properties should be changed</param>
        /// <param name="subject">The new subject for this thread</param>
        /// <param name="isSticky">The new value for IsSticky</param>
        /// <param name="isClosed">The new value for IsClosed</param>
        /// <returns></returns>
        public static bool ModifyThreadProperties(int threadID, string subject, bool isSticky, bool isClosed)
        {
            // load the entity from the database
            ThreadEntity thread = ThreadGuiHelper.GetThread(threadID);

            if (thread == null)
            {
                // not found
                return(false);
            }

            // update the fields with new values
            thread.Subject  = subject;
            thread.IsSticky = isSticky;
            thread.IsClosed = isClosed;

            // save the updated entity back to the database
            return(thread.Save());
        }
Пример #5
0
        /// <summary>
        /// Marks the thread as un-done, and add it to the default queue of the forum.
        /// </summary>
        /// <param name="threadID">Thread ID</param>
        /// <returns></returns>
        public static bool UnMarkThreadAsDone(int threadID, int userID)
        {
            // load the entity from the database
            ThreadEntity thread = ThreadGuiHelper.GetThread(threadID);

            if (thread == null)
            {
                // not found
                return(false);
            }

            thread.MarkedAsDone = false;

            ForumEntity forum = new ForumEntity(thread.ForumID);

            // Save the thread and add it to the default queue of the forum.
            Transaction trans = new Transaction(IsolationLevel.ReadCommitted, "MarkThreadUnDone");

            trans.Add(thread);
            try
            {
                thread.Save();

                if ((forum.Fields.State == EntityState.Fetched) && (forum.DefaultSupportQueueID.HasValue))
                {
                    // not in a queue, and the forum has a default queue. Add the thread to the queue of the forum
                    SupportQueueManager.AddThreadToQueue(threadID, forum.DefaultSupportQueueID.Value, userID, trans);
                }

                trans.Commit();
                return(true);
            }
            catch
            {
                // rollback transaction
                trans.Rollback();
                throw;
            }
            finally
            {
                trans.Dispose();
            }
        }
Пример #6
0
        /// <summary>
        /// Sends email to all users subscribed to a specified thread, except the user who initiated the thread update.
        /// </summary>
        /// <param name="threadID">The thread that was updated.</param>
        /// <param name="initiatedByUserID">The user who initiated the update (who will not receive notification).</param>
        private static void SendThreadReplyNotifications(int threadID, int initiatedByUserID, string emailTemplate,
                                                         Dictionary <string, string> emailData)
        {
            // get list of subscribers to thread, minus the initiator. Do this by fetching the subscriptions plus the related user entity entity instances.
            // The related user entities are loaded using a prefetch path.
            var qf = new QueryFactory();
            var q  = qf.ThreadSubscription
                     .Where((ThreadSubscriptionFields.ThreadID == threadID).And(ThreadSubscriptionFields.UserID != initiatedByUserID))
                     .WithPath(ThreadSubscriptionEntity.PrefetchPathUser);
            ThreadSubscriptionCollection subscriptions = new ThreadSubscriptionCollection();

            subscriptions.GetMulti(q);
            if (subscriptions.Count <= 0)
            {
                // no subscriptions, nothing to do
                return;
            }

            // now collect all email addresses into an array so we can pass that to the email routine.
            string[] toAddresses = new string[subscriptions.Count];

            for (int i = 0; i < subscriptions.Count; i++)
            {
                toAddresses[i] = subscriptions[i].User.EmailAddress;
            }

            // use template to construct message to send.
            StringBuilder mailBody       = new StringBuilder(emailTemplate);
            string        applicationURL = string.Empty;

            emailData.TryGetValue("applicationURL", out applicationURL);

            if (!string.IsNullOrEmpty(emailTemplate))
            {
                // Use the existing template to format the body
                string siteName = string.Empty;
                emailData.TryGetValue("siteName", out siteName);

                string threadSubject = string.Empty;
                string threadUrl     = string.Empty;

                ThreadEntity thread = ThreadGuiHelper.GetThread(threadID);
                if (thread != null)
                {
                    threadSubject = thread.Subject;
                    threadUrl     = applicationURL + string.Format("Messages.aspx?ThreadID={0}", thread.ThreadID);
                }
                else
                {
                    // thread doesn't exist, exit
                    return;
                }

                mailBody.Replace("[SiteURL]", applicationURL);
                mailBody.Replace("[SiteName]", siteName);
                mailBody.Replace("[ThreadSubject]", threadSubject);
                mailBody.Replace("[ThreadURL]", threadUrl);
            }

            // format the subject
            string subject = string.Empty;

            emailData.TryGetValue("emailThreadNotificationSubject", out subject);
            subject += applicationURL;

            string fromAddress = string.Empty;

            emailData.TryGetValue("defaultFromEmailAddress", out fromAddress);

            try
            {
                //send message
                HnDGeneralUtils.SendEmail(subject, mailBody.ToString(), fromAddress, toAddresses, emailData, true);
            }
            catch (SmtpFailedRecipientsException)
            {
                // swallow as it shouldn't have any effect on further operations
            }
            catch (SmtpException)
            {
                // swallow, as there's nothing we can do
            }
            // rest: problematic, so bubble upwards.
        }