⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 posts.cs

📁 微软的.NET论坛的源代码(COOL!!!)
💻 CS
📖 第 1 页 / 共 2 页
字号:
        /// <summary>
        /// This method returns a listing of the messages in a given thread using paging.
        /// </summary>
        /// <param name="PostID">Specifies the PostID of a post that belongs to the thread that we are 
        /// interested in grabbing the messages from.</param>
        /// <returns>A PostCollection containing the posts in the thread.</returns>
        /// 
        // ********************************************************************/ 
        public static PostCollection GetThreadByPostID(int postID, int currentPageIndex, int defaultPageSize, int sortBy, int sortOrder) {
            // Create Instance of the IWebForumsDataProviderBase
            IWebForumsDataProviderBase dp = DataProvider.Instance();

            return dp.GetThreadByPostID(postID, currentPageIndex, defaultPageSize, sortBy, sortOrder, HttpContext.Current.User.Identity.Name);			
        }

        // *********************************************************************
        //  GetThread
        //
        /// <summary>
        /// This method returns a listing of the messages in a given thread.
        /// </summary>
        /// <param name="ThreadID">Specifies the ThreadID that we are interested in grabbing the
        /// messages from.</param>
        /// <returns>A PostCollection containing the posts in the thread.</returns>
        /// 
        // ********************************************************************/ 
        public static PostCollection GetThread(int threadID) {
            // Create Instance of the IWebForumsDataProviderBase
            IWebForumsDataProviderBase dp = DataProvider.Instance();

            return dp.GetThread(threadID);			
        }

	
        // *********************************************************************
        //  GetAllMessages
        //
        /// <summary>
        /// This method returns all of the messages for a particular forum 
        /// (specified by ForumID) and returns the messages in a particular
        /// format (specified by ForumView).
        /// </summary>
        /// <param name="ForumID">The ID of the Forum whose posts you are interested in retrieving.</param>
        /// <param name="ForumView">How to view the posts.  The three options are: Flat, Mixed, and Threaded.</param>
        /// <param name="PagesBack">How many pages back of posts to view.  Each forum has a 
        /// parameter indicating how many days worth of posts to show per page.</param>
        /// <returns>A PostCollection object containing the posts for the particular forum that fall within
        /// the particular page specified by PagesBack.</returns>
        /// 
        // ********************************************************************/ 
        public static PostCollection GetAllMessages(int forumID, ViewOptions forumView, int pagesBack) {
            // Create Instance of the IWebForumsDataProviderBase
            IWebForumsDataProviderBase dp = DataProvider.Instance();

            // make sure ForumView is set
            if (forumView == ViewOptions.NotSet)
                forumView = (ViewOptions) Globals.DefaultForumView;

            return dp.GetAllMessages(forumID, forumView, pagesBack);			
        }


        // *********************************************************************
        //  GetTotalPostCount
        //
        /// <summary>
        /// Returns the total count of all posts in the system
        /// </summary>
        /// <returns>A count of the total posts</returns>
        /// 
        // ********************************************************************/ 
        public static int GetTotalPostCount() {
            // Create Instance of the IWebForumsDataProviderBase
            IWebForumsDataProviderBase dp = DataProvider.Instance();

            return dp.GetTotalPostCount();

        }


        // *********************************************************************
        //  AddPost
        //
        /// <summary>
        /// This method Adds a new post and returns a Post object containing information about the
        /// newly added post.
        /// </summary>
        /// <param name="PostToAdd">A Post object containing information about the post to add.
        /// This Post object need only have the following properties set: Subject, Body, Username,
        /// and ParentID or ForumID.  If the post is a new post, set ForumID; if it is a reply to
        /// an existing post, set the ParentID to the ID of the Post that is being replied to.</param>
        /// <returns>A Post object containing information about the newly added post.</returns>
        /// <remarks>The Post object being returned by the AddPost method indicates the PostID of the
        /// newly added post and specifies if the post is approved for viewing or not.</remarks>
        /// 
        // ********************************************************************/ 
        public static Post AddPost(Post postToAdd) {
            // convert the subject to the formatted version before adding the post
            postToAdd.Subject = PostSubjectRawToFormatted(postToAdd.Subject);

            // Create Instance of the IWebForumsDataProviderBase
            IWebForumsDataProviderBase dp = DataProvider.Instance();

            Post newPost = dp.AddPost(postToAdd, HttpContext.Current.User.Identity.Name);

            // send emails to those that are tracking the thread (if it was an approved post)
            if (newPost.Approved)
                Emails.SendThreadTrackingEmails(newPost.PostID);
            else
                Emails.SendModeratorsNotification(newPost.ThreadID);

            return newPost;
        }

        // *********************************************************************
        //  UpdatePost
        //
        /// <summary>
        /// This method updates a post (called from the admin/moderator editing the post).
        /// </summary>
        /// <param name="UpdatedPost">Changes needing to be made to a particular post.  The PostID
        /// represents to post to update.</param>
        /// 
        // ********************************************************************/ 
        public static void UpdatePost(Post post, string editedBy) {
            post.Subject = PostSubjectRawToFormatted(post.Subject);

            // Create Instance of the IWebForumsDataProviderBase
            IWebForumsDataProviderBase dp = DataProvider.Instance();

            dp.UpdatePost(post, editedBy);
        }

	
        // *********************************************************************
        //  PostSubjectRawToFormatted
        //
        /// <summary>
        /// Converts the subject line from raw text to the proper display.
        /// </summary>
        /// <param name="RawMessageSubject">The raw text of the subject line.</param>
        /// <returns>A prepared subject line.</returns>
        /// <remarks>PostSubjectRawToFormatted simply strips out any HTML tags from the subject.  It is this
        /// prepared subject line that is stored in the database.</remarks>
        /// 
        // ********************************************************************/ 
        public static String PostSubjectRawToFormatted(String rawMessageSubject) {		
            String strSubject = rawMessageSubject;
			
            // strip the HTML - i.e., turn < into &lt;, > into &gt;
            //strSubject = strSubject.Replace("<", "&lt;");
            //strSubject = strSubject.Replace(">", "&gt;");				

            strSubject = HttpContext.Current.Server.HtmlEncode(strSubject);
			
            return strSubject;
        } 
		

        // *********************************************************************
        //  DeletePost
        //
        /// <summary>
        /// Permanently deletes a post and all of its replies.
        /// </summary>
        /// <param name="PostID">The ID of the Post to delete.</param>
        /// <remarks>Use with care; keep in mind that this method deletes the specified post *and*
        /// all of the posts that are replies to this post.</remarks>
        /// 
        // ********************************************************************/ 
        public static void DeletePost(int postID, string approvedBy, string reason) {
            // send the reason why the post was deleted
            if (reason.Length == 0) reason = "NO REASON GIVEN";
            
            Emails.SendEmail(((Post) Posts.GetPost(postID, null)).Username, EmailTypeEnum.MessageDeleted, postID, reason);

            // Create Instance of the IWebForumsDataProviderBase
            IWebForumsDataProviderBase dp = DataProvider.Instance();

            dp.DeletePost(postID, approvedBy, reason);
        }

    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -