示例#1
0
        /// <summary>
        /// Constructs a TypedList with all the messages in the thread given. Poster info is included, so the
        /// returned dataview is bindable at once to the message list repeater.
        /// </summary>
        /// <param name="threadID">ID of Thread which messages should be returned</param>
        /// <param name="pageNo">The page no.</param>
        /// <param name="pageSize">Size of the page.</param>
        /// <returns>TypedList with all messages in the thread for the page specified</returns>
        public static MessagesInThreadTypedList GetAllMessagesInThreadAsTypedList(int threadID, int pageNo, int pageSize)
        {
            // we'll use a typedlist, MessagesInThread to pull the necessary data from the db. The typedlist contains fields from
            // message, user and usertitle.
            MessagesInThreadTypedList messages = new MessagesInThreadTypedList();

            //create the filter with the threadID passed to the method.
            PredicateExpression filter = new PredicateExpression(MessageFields.ThreadID == threadID);

            // Sort Messages on posting date, ascending, so the first post is located on top.
            SortExpression sorter = new SortExpression(MessageFields.PostingDate.Ascending());

            // fetch the data into the typedlist. Pass in the paging information as well, to perform server-side paging.
            messages.Fill(0, sorter, true, filter, null, null, pageNo, pageSize);

            // update thread entity directly inside the DB with a non-transactional update statement so the # of views is increased by one.
            ThreadEntity updater = new ThreadEntity();

            // set the NumberOfViews field to an expression which increases it by 1
            updater.Fields[(int)ThreadFieldIndex.NumberOfViews].ExpressionToApply = (ThreadFields.NumberOfViews + 1);
            updater.IsNew = false;

            // update the entity directly, and filter on the PK
            ThreadCollection threads = new ThreadCollection();

            threads.UpdateMulti(updater, (ThreadFields.ThreadID == threadID));

            // return the constructed typedlist
            return(messages);
        }
示例#2
0
		/// <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);
            }
		}
示例#3
0
        /// <summary>
        /// Deletes the user with the ID passed in. Will reset all posts made by the user to the userid 0. 
        /// </summary>
        /// <param name="userID">The user ID.</param>
        /// <remarks>Can't delete user 0</remarks>
        /// <returns>true if succeeded, false otherwise</returns>
        public static bool DeleteUser(int userID)
        {
            if(userID == 0)
            {
                // can't delete the Anonymous coward user.
                return false;
            }

            UserEntity toDelete = UserGuiHelper.GetUser(userID);
            if(toDelete==null)
            {
                // user doesn't exist
                return false;
            }

            // all actions have to take place in a transaction.
            Transaction trans = new Transaction(IsolationLevel.ReadCommitted, "DeleteUser");

            try
            {
                // we'll first update all PostedByUserId fields of all messages which are posted by the user to delete.
                MessageEntity messageUpdater = new MessageEntity();
                messageUpdater.PostedByUserID = 0;	// reset to AC.
                MessageCollection messages = new MessageCollection();
                trans.Add(messages);	// add to the transaction
                // update all entities directly in the DB, which match the following filter and update them with the new values set in messageUpdater.
                messages.UpdateMulti(messageUpdater, (MessageFields.PostedByUserID == userID));

                // set the startuser of threads started by this user to 0
                ThreadEntity threadUpdater = new ThreadEntity();
                threadUpdater.StartedByUserID = 0;
                ThreadCollection threads = new ThreadCollection();
                trans.Add(threads);
                threads.UpdateMulti(threadUpdater, (ThreadFields.StartedByUserID == userID));

                // remove the user from the UserRoles set, as the user shouldn't be in any roles.
                RoleUserCollection roleUsersDeleter = new RoleUserCollection();
                trans.Add(roleUsersDeleter);
                // delete all entities directly from the DB which match the following filter.
                roleUsersDeleter.DeleteMulti(RoleUserFields.UserID == userID);

                // delete all bookmarks of user
                BookmarkCollection bookmarkDeleter = new BookmarkCollection();
                trans.Add(bookmarkDeleter);
                // delete all bookmarks for this user directly from the DB using the following filter.
                bookmarkDeleter.DeleteMulti(BookmarkFields.UserID == userID);

                // delete all audit data
                AuditDataCoreCollection auditDataDeleter = new AuditDataCoreCollection();
                // first fetch it, then delete all entities from the collection, as the audit data is in an inheritance hierarchy of TargetPerEntity which can't
                // be deleted directly from the db.
                trans.Add(auditDataDeleter);
                auditDataDeleter.GetMulti(AuditDataCoreFields.UserID == userID);
                auditDataDeleter.DeleteMulti();

                // set IP bans set by this user to userid 0
                IPBanEntity ipbanUpdater = new IPBanEntity();
                ipbanUpdater.IPBanSetByUserID = 0;
                IPBanCollection ipBans = new IPBanCollection();
                trans.Add(ipBans);
                ipBans.UpdateMulti(ipbanUpdater, (IPBanFields.IPBanSetByUserID == userID));

                // delete threadsubscriptions
                ThreadSubscriptionCollection threadSubscriptionsDeleter = new ThreadSubscriptionCollection();
                trans.Add(threadSubscriptionsDeleter);
                threadSubscriptionsDeleter.DeleteMulti(ThreadSubscriptionFields.UserID == userID);

                // remove supportqueuethread claims
                SupportQueueThreadCollection supportQueueThreads = new SupportQueueThreadCollection();
                trans.Add(supportQueueThreads);
                supportQueueThreads.DeleteMulti(SupportQueueThreadFields.ClaimedByUserID == userID);

                // set all placed in queue references to userid 0, so the threads stay in the queues.
                SupportQueueThreadEntity supportQueueThreadUpdater = new SupportQueueThreadEntity();
                supportQueueThreadUpdater.PlacedInQueueByUserID=0;
                supportQueueThreads.UpdateMulti(supportQueueThreadUpdater, (SupportQueueThreadFields.PlacedInQueueByUserID == userID));

                // now delete the actual user entity
                trans.Add(toDelete);
                toDelete.Delete();

                // all done
                trans.Commit();
                return true;
            }
            catch
            {
                trans.Rollback();
                throw;
            }
            finally
            {
                trans.Dispose();
            }
        }
示例#4
0
		/// <summary>
		/// Constructs a TypedList with all the messages in the thread given. Poster info is included, so the
		/// returned dataview is bindable at once to the message list repeater.
		/// </summary>
		/// <param name="threadID">ID of Thread which messages should be returned</param>
		/// <param name="pageNo">The page no.</param>
		/// <param name="pageSize">Size of the page.</param>
		/// <returns>TypedList with all messages in the thread for the page specified</returns>
		public static MessagesInThreadTypedList GetAllMessagesInThreadAsTypedList(int threadID, int pageNo, int pageSize)
		{
			// we'll use a typedlist, MessagesInThread to pull the necessary data from the db. The typedlist contains fields from
			// message, user and usertitle. 
			MessagesInThreadTypedList messages = new MessagesInThreadTypedList(); 

			//create the filter with the threadID passed to the method.
			PredicateExpression filter = new PredicateExpression(MessageFields.ThreadID == threadID);

			// Sort Messages on posting date, ascending, so the first post is located on top. 
			SortExpression sorter = new SortExpression(MessageFields.PostingDate.Ascending());

			// fetch the data into the typedlist. Pass in the paging information as well, to perform server-side paging. 
			messages.Fill(0, sorter, true, filter, null, null, pageNo, pageSize);

			// update thread entity directly inside the DB with a non-transactional update statement so the # of views is increased by one.
			ThreadEntity updater = new ThreadEntity();
			// set the NumberOfViews field to an expression which increases it by 1
			updater.Fields[(int)ThreadFieldIndex.NumberOfViews].ExpressionToApply = (ThreadFields.NumberOfViews + 1);
			updater.IsNew = false;

			// update the entity directly, and filter on the PK
			ThreadCollection threads = new ThreadCollection();
			threads.UpdateMulti(updater, (ThreadFields.ThreadID == threadID));
			
			// return the constructed typedlist
			return messages;
		}
示例#5
0
        /// <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);
            }
        }
示例#6
0
        /// <summary>
        /// Deletes the user with the ID passed in. Will reset all posts made by the user to the userid 0.
        /// </summary>
        /// <param name="userID">The user ID.</param>
        /// <remarks>Can't delete user 0</remarks>
        /// <returns>true if succeeded, false otherwise</returns>
        public static bool DeleteUser(int userID)
        {
            if (userID == 0)
            {
                // can't delete the Anonymous coward user.
                return(false);
            }

            UserEntity toDelete = UserGuiHelper.GetUser(userID);

            if (toDelete == null)
            {
                // user doesn't exist
                return(false);
            }

            // all actions have to take place in a transaction.
            Transaction trans = new Transaction(IsolationLevel.ReadCommitted, "DeleteUser");

            try
            {
                // we'll first update all PostedByUserId fields of all messages which are posted by the user to delete.
                MessageEntity messageUpdater = new MessageEntity();
                messageUpdater.PostedByUserID = 0;      // reset to AC.
                MessageCollection messages = new MessageCollection();
                trans.Add(messages);                    // add to the transaction
                // update all entities directly in the DB, which match the following filter and update them with the new values set in messageUpdater.
                messages.UpdateMulti(messageUpdater, (MessageFields.PostedByUserID == userID));

                // set the startuser of threads started by this user to 0
                ThreadEntity threadUpdater = new ThreadEntity();
                threadUpdater.StartedByUserID = 0;
                ThreadCollection threads = new ThreadCollection();
                trans.Add(threads);
                threads.UpdateMulti(threadUpdater, (ThreadFields.StartedByUserID == userID));

                // remove the user from the UserRoles set, as the user shouldn't be in any roles.
                RoleUserCollection roleUsersDeleter = new RoleUserCollection();
                trans.Add(roleUsersDeleter);
                // delete all entities directly from the DB which match the following filter.
                roleUsersDeleter.DeleteMulti(RoleUserFields.UserID == userID);

                // delete all bookmarks of user
                BookmarkCollection bookmarkDeleter = new BookmarkCollection();
                trans.Add(bookmarkDeleter);
                // delete all bookmarks for this user directly from the DB using the following filter.
                bookmarkDeleter.DeleteMulti(BookmarkFields.UserID == userID);

                // delete all audit data
                AuditDataCoreCollection auditDataDeleter = new AuditDataCoreCollection();
                // first fetch it, then delete all entities from the collection, as the audit data is in an inheritance hierarchy of TargetPerEntity which can't
                // be deleted directly from the db.
                trans.Add(auditDataDeleter);
                auditDataDeleter.GetMulti(AuditDataCoreFields.UserID == userID);
                auditDataDeleter.DeleteMulti();

                // set IP bans set by this user to userid 0
                IPBanEntity ipbanUpdater = new IPBanEntity();
                ipbanUpdater.IPBanSetByUserID = 0;
                IPBanCollection ipBans = new IPBanCollection();
                trans.Add(ipBans);
                ipBans.UpdateMulti(ipbanUpdater, (IPBanFields.IPBanSetByUserID == userID));

                // delete threadsubscriptions
                ThreadSubscriptionCollection threadSubscriptionsDeleter = new ThreadSubscriptionCollection();
                trans.Add(threadSubscriptionsDeleter);
                threadSubscriptionsDeleter.DeleteMulti(ThreadSubscriptionFields.UserID == userID);

                // remove supportqueuethread claims
                SupportQueueThreadCollection supportQueueThreads = new SupportQueueThreadCollection();
                trans.Add(supportQueueThreads);
                supportQueueThreads.DeleteMulti(SupportQueueThreadFields.ClaimedByUserID == userID);

                // set all placed in queue references to userid 0, so the threads stay in the queues.
                SupportQueueThreadEntity supportQueueThreadUpdater = new SupportQueueThreadEntity();
                supportQueueThreadUpdater.PlacedInQueueByUserID = 0;
                supportQueueThreads.UpdateMulti(supportQueueThreadUpdater, (SupportQueueThreadFields.PlacedInQueueByUserID == userID));

                // now delete the actual user entity
                trans.Add(toDelete);
                toDelete.Delete();

                // all done
                trans.Commit();
                return(true);
            }
            catch
            {
                trans.Rollback();
                throw;
            }
            finally
            {
                trans.Dispose();
            }
        }