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

📄 posts.cs

📁 微软的.NET论坛的源代码(COOL!!!)
💻 CS
📖 第 1 页 / 共 2 页
字号:
using System;
using System.Collections;
using System.Web;
using System.IO;
using System.Web.Caching;
using AspNetForums.Components;

namespace AspNetForums {

    // *********************************************************************
    //  Posts
    //
    /// <summary>
    /// This class contains methods for working with an individual post.  There are methods to
    /// Add a New Post, Update an Existing Post, retrieve a single post, etc.
    /// </summary>
    // ***********************************************************************/
    public class Posts {

        // *********************************************************************
        //  GetPost
        //
        /// <summary>
        /// Returns information about a particular post.
        /// </summary>
        /// <param name="PostID">The ID of the Post to return.</param>
        /// <returns>A Post object with the spcified Post's information.</returns>
        /// <remarks>This method returns information about a particular post.  If the post specified is
        /// not found, a PostNotFoundException exception is thrown.  If you need more detailed
        /// information, such as the PostID of the next/prev posts in the thread, or if the current user
        /// has email tracking enabled for the thread the post appears in, use the GetPostDetails
        /// method.<seealso cref="GetPostDetails"/></remarks>
        /// 
        // ***********************************************************************/
        public static Post GetPost(int postID, string username) {

            // We only want to call this code once per request
            if (HttpContext.Current.Items["Post" + postID] != null) {
                return (Post) HttpContext.Current.Items["Post" + postID];
            } else {
                Post post;

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

                post = dp.GetPost(postID, username, true);

                // Store in context of current request
                HttpContext.Current.Items["Post" + postID] = post;

                return post;
            }
        }


        // *********************************************************************
        //  GetPostDetails
        //
        /// <summary>
        /// Returns more detailed information about a Post than GetPost.
        /// </summary>
        /// <param name="PostID">The ID of the Post to obtain information about.</param>
        /// <param name="Username">The Username of the user viewing the post.</param>
        /// <param name="ConvertPostBodyFromRawToFormatted">A Boolean indicating whether or not
        /// to convert the post's raw database format into the HTML-ready formatted output.</param>
        /// <returns>A PostDetails object with detailed information about the post</returns>
        /// <remarks>GetPostDetails returns five bits of information that the GetPost method fails to:
        /// the PostID of the next/prev posts in the thread, the PostID of the first post in the
        /// next/prev threads, and whether or not the user viewing the post has email thread tracking
        /// turned on for the thread that the post belongs in.  If you don't need this extra information,
        /// call the less resource intensive GetPost. <seealso cref="GetPost"/></remarks>
        /// 
        // ***********************************************************************/
        public static PostDetails GetPostDetails(int postID, String username, bool convertPostBodyFromRawToFormatted) {
            // Create Instance of the IWebForumsDataProviderBase
            IWebForumsDataProviderBase dp = DataProvider.Instance();

            if (convertPostBodyFromRawToFormatted) {
                PostDetails retPost = dp.GetPostDetails(postID, username);
                retPost.Body = Globals.FormatPostBody(retPost.Body);
                return retPost;
            }
            else
                return dp.GetPostDetails(postID, username);
        }


        // *********************************************************************
        //  GetPostDetails
        //
        /// <summary>
        /// Returns more detailed information about a Post than GetPost.
        /// </summary>
        /// <param name="PostID">The ID of the Post to obtain information about.</param>
        /// <param name="Username">The Username of the user viewing the post.</param>
        /// <returns>A PostDetails object with detailed information about the post</returns>
        /// <remarks>GetPostDetails returns five bits of information that the GetPost method fails to:
        /// the PostID of the next/prev posts in the thread, the PostID of the first post in the
        /// next/prev threads, and whether or not the user viewing the post has email thread tracking
        /// turned on for the thread that the post belongs in.  If you don't need this extra information,
        /// call the less resource intensive GetPost. <seealso cref="GetPost"/></remarks>
        /// 
        // ***********************************************************************/
        public static PostDetails GetPostDetails(int postID, String username) {
            // Create Instance of the IWebForumsDataProviderBase
            IWebForumsDataProviderBase dp = DataProvider.Instance();

            return dp.GetPostDetails(postID, username);
        }


        // *********************************************************************
        //  ReverseThreadTrackingOptions
        //
        /// <summary>
        /// This method reverses a user's thread tracking options for the thread containing a
        /// particular Post.
        /// </summary>
        /// <param name="Username">The user whose thread tracking options you wish to change.</param>
        /// <param name="PostID">The post of the thread whose tracking option you wish to reverse for
        /// the specified user.</param>
        /// 
        // ***********************************************************************/
        public static void ReverseThreadTrackingOptions(String username, int postID) {
            // Create Instance of the IWebForumsDataProviderBase
            IWebForumsDataProviderBase dp = DataProvider.Instance();

            dp.ReverseThreadTracking(username, postID);
        }


        // *********************************************************************
        //  MarkPostAsRead
        //
        /// <summary>
        /// Given a post id, marks it as read in the database for a user.
        /// </summary>
        /// <param name="postID">Id of post to mark as read</param>
        /// <param name="username">Mark read for this user</param>
        /// 
        // ********************************************************************/ 
        public static void MarkPostAsRead(int postID, string username) {
            // Create Instance of the IWebForumsDataProviderBase
            IWebForumsDataProviderBase dp = DataProvider.Instance();

            dp.MarkPostAsRead(postID, username);
        }

        // *********************************************************************
        //  GetThreadByPostID
        //
        /// <summary>
        /// This method returns a listing of the messages in a given thread.
        /// </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) {

            // This method may be called multiple times for a single request
            // we only want to call it once and use the same results for 
            // subsequent calls in the same request chaing
            if (HttpContext.Current.Items["Thread" + postID] != null) {
                return (PostCollection) HttpContext.Current.Items["Thread" + postID];
            } else {
                PostCollection posts;

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

                // Get the post collection
                posts = dp.GetThreadByPostID(postID, HttpContext.Current.User.Identity.Name);

                // Add to the context
                HttpContext.Current.Items["Thread" + postID] = posts;

                // Return the posts
                return posts;
            }
        }
	
        // *********************************************************************
        //  GetThreadByPostID
        //

⌨️ 快捷键说明

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