/// <summary> /// Gets all forum entities which belong to a given section. /// </summary> /// <param name="sectionID">The section ID from which forums should be retrieved</param> /// <returns>Entity collection with entities for all forums in this section sorted alphabitacally</returns> public static ForumCollection GetAllForumsInSection(int sectionID) { var q = new QueryFactory().Forum .Where(ForumFields.SectionID == sectionID) .OrderBy(ForumFields.OrderNo.Ascending(), ForumFields.ForumName.Ascending()); var toReturn = new ForumCollection(); toReturn.GetMulti(q); return(toReturn); }
/// <summary> /// Updates the user/forum/thread statistics after a message insert. Also makes sure if the thread isn't in a queue and the forum has a default support /// queue that the thread is added to that queue /// </summary> /// <param name="threadID">The thread ID.</param> /// <param name="userID">The user ID.</param> /// <param name="transactionToUse">The transaction to use.</param> /// <param name="postingDate">The posting date.</param> /// <param name="addToQueueIfRequired">if set to true, the thread will be added to the default queue of the forum the thread is in, if the forum /// has a default support queue and the thread isn't already in a queue.</param> /// <remarks>Leaves the passed in transaction open, so it doesn't commit/rollback, it just performs a set of actions inside the /// passed in transaction.</remarks> internal static void UpdateStatisticsAfterMessageInsert(int threadID, int userID, Transaction transactionToUse, DateTime postingDate, bool addToQueueIfRequired, bool subscribeToThread) { // user statistics UserEntity userUpdater = new UserEntity(); // set the amountofpostings field to an expression so it will be increased with 1. userUpdater.Fields[(int)UserFieldIndex.AmountOfPostings].ExpressionToApply = (UserFields.AmountOfPostings + 1); UserCollection users = new UserCollection(); transactionToUse.Add(users); users.UpdateMulti(userUpdater, (UserFields.UserID == userID)); // update directly on the DB. // thread statistics ThreadEntity threadUpdater = new ThreadEntity(); threadUpdater.ThreadLastPostingDate = postingDate; threadUpdater.MarkedAsDone = false; ThreadCollection threads = new ThreadCollection(); transactionToUse.Add(threads); threads.UpdateMulti(threadUpdater, (ThreadFields.ThreadID == threadID)); // forum statistics. Load the forum from the DB, as we need it later on. Use a fieldcompareset predicate to fetch the forum as we don't know the // forumID as we haven't fetched the thread ForumCollection forums = new ForumCollection(); transactionToUse.Add(forums); // use a fieldcompare set predicate to select the forumid based on the thread. This filter is equal to // WHERE ForumID == (SELECT ForumID FROM Thread WHERE ThreadID=@ThreadID) var forumFilter = new FieldCompareSetPredicate( ForumFields.ForumID, ThreadFields.ForumID, SetOperator.Equal, (ThreadFields.ThreadID == threadID)); forums.GetMulti(forumFilter); ForumEntity containingForum = null; if(forums.Count>0) { // forum found. There's just one. containingForum = forums[0]; containingForum.ForumLastPostingDate = postingDate; // save the forum. Just save the collection forums.SaveMulti(); } if(addToQueueIfRequired) { // If the thread involved isn't in a queue, place it in the default queue of the forum (if applicable) SupportQueueEntity containingQueue = SupportQueueGuiHelper.GetQueueOfThread(threadID, transactionToUse); if((containingQueue == null) && (containingForum != null) && (containingForum.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, containingForum.DefaultSupportQueueID.Value, userID, transactionToUse); } } //subscribe to thread if indicated if(subscribeToThread) { UserManager.AddThreadToSubscriptions(threadID, userID, transactionToUse); } }
/// <summary> /// Gets all forum entities which belong to a given section. /// </summary> /// <param name="sectionID">The section ID from which forums should be retrieved</param> /// <returns>Entity collection with entities for all forums in this section sorted alphabitacally</returns> public static ForumCollection GetAllForumsInSection(int sectionID) { var q = new QueryFactory().Forum .Where(ForumFields.SectionID == sectionID) .OrderBy(ForumFields.OrderNo.Ascending(), ForumFields.ForumName.Ascending()); var toReturn = new ForumCollection(); toReturn.GetMulti(q); return toReturn; }