Beispiel #1
0
    private HtmlGenericControl CreateContent(Post post)
    {
        //Create the controller;
        LS Controller = new LS();

        //User Data
        int    voteCount = 0;
        string userName  = null;

        //Create the Div
        HtmlGenericControl ContentDiv = new HtmlGenericControl("div");

        ContentDiv.ID = post.PostID.ToString();
        ContentDiv.Attributes["class"] = post.ContainsImage ? "CommentPostContainerwImage" : "CommentPostContainerwoImage";
        ContentDiv.Attributes["style"] = "margin: 0 auto;  margin-bottom:15px; background-color:#464749; border-radius: 10px;  ";

        if (Session["User"] != null)
        {
            userName  = Session["User"].ToString();
            voteCount = Controller.FindUserVoteForPost(post.PostID, userName);
        }

        //Create div to hold the upvote, downvote, vote count and comment count
        HtmlGenericControl ToolLine = new HtmlGenericControl("div");

        ToolLine.Attributes["class"] = "CommentNavLine";

        //Create the upvote control
        ImageButton Upvote = new ImageButton();

        Upvote.ID       = post.PostID.ToString() + "uv";
        Upvote.CssClass = "CommentPostUpvote";

        if (voteCount > 0)
        {
            Upvote.ImageUrl = "image/UpVoteOn.png";
        }
        else
        {
            Upvote.ImageUrl = "image/UpVoteOff.png";
        }

        Upvote.CommandArgument = post.PostID.ToString();
        Upvote.Click          += new ImageClickEventHandler(Upvote_Click);
        ToolLine.Controls.Add(Upvote);

        //Create the downvote control
        ImageButton Downvote = new ImageButton();

        Downvote.ID       = post.PostID.ToString() + "dv";
        Downvote.CssClass = "CommentPostDownvote";
        ToolLine.Controls.Add(Downvote);

        if (voteCount < 0)
        {
            Downvote.ImageUrl = "image/DownVoteOn.png";
        }
        else
        {
            Downvote.ImageUrl = "image/DownVoteOff.png";
        }


        //Create the comment counter lbl(Will be hyperlink in the future)
        Label CommentCountLbl = new Label();

        CommentCountLbl.ID        = post.PostID.ToString() + "cc";
        CommentCountLbl.CssClass  = "CommentCommentCount";
        CommentCountLbl.ForeColor = System.Drawing.Color.WhiteSmoke;
        CommentCountLbl.Text      = "Comments: " + Controller.GetThreadCount((int)post.MainPostReferenceID) + "";
        ToolLine.Controls.Add(CommentCountLbl);

        //Create the Vote count Label
        Label VotecountLbl = new Label();

        VotecountLbl.ID        = post.PostID.ToString() + "vc";
        VotecountLbl.CssClass  = "CommentPostVoteCount";
        VotecountLbl.ForeColor = System.Drawing.Color.WhiteSmoke;
        VotecountLbl.Text      = (post.UpCount - post.DownCount) + "";
        ToolLine.Controls.Add(VotecountLbl);

        //Add the tooline div to the contentDiv
        ContentDiv.Controls.Add(ToolLine);

        //Create the Post user Lbl
        Label PostUserLbl = new Label();

        PostUserLbl.ID        = post.PostID.ToString() + "pu";
        PostUserLbl.CssClass  = "CommentPostUser";
        PostUserLbl.ForeColor = System.Drawing.Color.WhiteSmoke;
        PostUserLbl.Text      = string.Format("Posted by: {0} on {1}", post.UserName, post.PostDate.ToShortDateString());
        ContentDiv.Controls.Add(PostUserLbl);

        //Create the Title Label
        Label TitleLbl = new Label();

        TitleLbl.ID        = post.PostID.ToString() + "tl";
        TitleLbl.Font.Size = 20;
        TitleLbl.ForeColor = System.Drawing.Color.WhiteSmoke;
        TitleLbl.CssClass  = "CommentPostTitle";
        TitleLbl.Text      = post.Title;
        ContentDiv.Controls.Add(TitleLbl);


        //Content whether image or text
        if (post.ContainsImage)
        {
            //Create the div that holds the anchor
            HtmlGenericControl ImageDiv = new HtmlGenericControl("div");
            ImageDiv.ID = post.PostID.ToString() + "ic";
            ImageDiv.Attributes["class"] = "ImageDivContent";
            ImageDiv.Attributes["style"] = "margin: 0 auto;";

            //Create the anchor that holds the img acts as a hyperlink

            //HtmlAnchor anchor = new HtmlAnchor();
            //anchor.HRef = "default.aspx"; //This can be changed later to be dynamic;


            //Create the image
            ImageButton img = new ImageButton();
            foreach (ImagePic ip in Controller.FindImagesByPostID(post.PostID))
            {
                img.CommandArgument          = post.PostID.ToString();
                img.Attributes["width"]      = "auto";
                img.Attributes["height"]     = "auto";
                img.Attributes["max-height"] = "400px";
                post.PostImages = Controller.FindImagesByPostID(post.PostID);
                img.ImageUrl    = ip.ImagePath;//"image/img150.png";
                ImageDiv.Controls.Add(img);
            }

            ContentDiv.Controls.Add(ImageDiv);
        }
        else
        {
            Label ContentLbl = new Label();
            ContentLbl.ID        = post.PostID.ToString() + "tl";
            ContentLbl.Font.Size = 16;
            ContentLbl.ForeColor = System.Drawing.Color.WhiteSmoke;
            ContentLbl.Text      = post.PostText;
            ContentDiv.Controls.Add(ContentLbl);
        }



        return(ContentDiv);
    }
Beispiel #2
0
        /// <summary>
        /// Creates the div that holds all of the post content
        /// </summary>
        /// <param name="post">Post object that contains all the data</param>
        /// <returns></returns>
        private HtmlGenericControl CreatePost(Post post)
        {
            //Create the controller;
            LS Controller = new LS();
            //Create the Div
            HtmlGenericControl PostDiv = new HtmlGenericControl("div");

            PostDiv.ID = post.PostID.ToString();
            PostDiv.Attributes["class"] = "PostContainer";
            PostDiv.Attributes["style"] = "margin: 0 auto;  margin-bottom:15px; background-color:#464749; border-radius: 10px;  ";

            // Check if a user is logged in; in not - voteCount = 0;
            int    voteCount = 0;
            string userName  = null;

            if (Session["User"] != null)
            {
                userName  = Session["User"].ToString();
                voteCount = Controller.FindUserVoteForPost(post.PostID, userName);
            }

            // Check if the user has voted on this post before and assign appropriate upvote/downvote image
            // int voteCount = Controller.FindUserVoteForPost(post.PostID, "Bob");



            //Create the upvote control
            ImageButton Upvote = new ImageButton();

            Upvote.ID       = post.PostID.ToString() + "uv";
            Upvote.CssClass = "PostUpvote";

            if (voteCount > 0)
            {
                Upvote.ImageUrl = "image/UpVoteOn.png";
            }
            else
            {
                Upvote.ImageUrl = "image/UpVoteOff.png";
            }

            Upvote.CommandArgument = post.PostID.ToString();
            Upvote.Click          += new ImageClickEventHandler(Upvote_Click);
            PostDiv.Controls.Add(Upvote);

            //Create the downvote control
            ImageButton Downvote = new ImageButton();

            Downvote.ID       = post.PostID.ToString() + "dv";
            Downvote.CssClass = "PostDownvote";

            if (voteCount < 0)
            {
                Downvote.ImageUrl = "image/DownVoteOn.png";
            }
            else
            {
                Downvote.ImageUrl = "image/DownVoteOff.png";
            }

            Downvote.CommandArgument = post.PostID.ToString();
            Downvote.Click          += new ImageClickEventHandler(Downvote_Click);
            PostDiv.Controls.Add(Downvote);

            //Create the Vote count Label
            Label VotecountLbl = new Label();

            VotecountLbl.ID        = post.PostID.ToString() + "vc";
            VotecountLbl.CssClass  = "PostVoteCount";
            VotecountLbl.ForeColor = System.Drawing.Color.WhiteSmoke;
            VotecountLbl.Text      = (post.UpCount - post.DownCount) + "";
            PostDiv.Controls.Add(VotecountLbl);

            //Create the comment counter lbl(Will be hyperlink in the future)
            Label CommentCountLbl = new Label();

            CommentCountLbl.ID        = post.PostID.ToString() + "cc";
            CommentCountLbl.CssClass  = "PostCommentCount";
            CommentCountLbl.ForeColor = System.Drawing.Color.WhiteSmoke;
            CommentCountLbl.Text      = "Comments: " + Controller.GetThreadCount((int)post.MainPostReferenceID) + "";
            PostDiv.Controls.Add(CommentCountLbl);

            //Create the Title Label(Will be hyperlink in the future)

            /*
             * HyperLink TitleHL = new HyperLink();
             * TitleHL.ID = post.PostID.ToString() + "hl";
             * TitleHL.Font.Size = 20;
             * TitleHL.ForeColor = System.Drawing.Color.WhiteSmoke;
             * TitleHL.Text = post.Title;
             */
            LinkButton TitleLB = new LinkButton();

            TitleLB.ID        = post.PostID.ToString() + "hl";
            TitleLB.Font.Size = 20;
            TitleLB.ForeColor = System.Drawing.Color.WhiteSmoke;
            TitleLB.Text      = post.Title;
            TitleLB.Click    += new EventHandler(LinkButton_click);
            if (post.ContainsImage)
            {
                TitleLB.CssClass = "PostTitlewImage";
            }
            else
            {
                TitleLB.CssClass = "PostTitlewoImage";
            }

            /*
             * Label TitleLbl = new Label();
             * TitleLbl.ID = post.PostID.ToString() + "tl";
             * TitleLbl.Font.Size = 20;
             * TitleLbl.ForeColor = System.Drawing.Color.WhiteSmoke;
             * TitleLbl.Text = post.Title;
             * if (post.ContainsImage)
             * {
             *  TitleLbl.CssClass = "PostTitlewImage";
             * }
             * else
             * {
             *  TitleLbl.CssClass = "PostTitlewoImage";
             * }
             */
            PostDiv.Controls.Add(TitleLB);



            //Create the Post date Lbl
            Label PostDateLbl = new Label();

            PostDateLbl.ID        = post.PostID.ToString() + "pd";
            PostDateLbl.CssClass  = "PostDate";
            PostDateLbl.ForeColor = System.Drawing.Color.WhiteSmoke;
            PostDateLbl.Text      = post.PostDate.ToLongDateString();
            PostDiv.Controls.Add(PostDateLbl);

            //Create the PostBy Label
            Label PostByLbl = new Label();

            PostByLbl.ID        = post.PostID.ToString() + "pb";
            PostByLbl.CssClass  = "PostUser";
            PostByLbl.ForeColor = System.Drawing.Color.WhiteSmoke;
            PostByLbl.Text      = "Submitted By: " + post.UserName;
            PostDiv.Controls.Add(PostByLbl);

            //Create Image if it contains image
            if (post.ContainsImage)
            {
                //Create the div that holds the anchor
                HtmlGenericControl ImageDiv = new HtmlGenericControl("div");
                ImageDiv.ID = post.PostID.ToString() + "ic";
                ImageDiv.Attributes["class"] = "ImageDivPreview";
                ImageDiv.Attributes["style"] = "margin: 0 auto;";

                //Create the anchor that holds the img acts as a hyperlink

                /*
                 * HtmlAnchor anchor = new HtmlAnchor();
                 * anchor.HRef = "default.aspx"; //This can be changed later to be dynamic;
                 */

                //Create the image
                Image img = new Image();
                img.Attributes["width"]  = "1000px";
                img.Attributes["height"] = "600px";
                post.PostImages          = Controller.FindImagesByPostID(post.PostID);
                img.ImageUrl             = post.PostImages[0].ImagePath;//"image/img150.png";

                /*
                 * System.Web.UI.WebControls.Image PostImage = new System.Web.UI.WebControls.Image();
                 * PostImage.ImageUrl = "image/img150.png"; //Link the image to file
                 */
                //Add the image to the anchor which is added to the div
                //anchor.Controls.Add(PostImage);
                ImageDiv.Controls.Add(img);
                PostDiv.Controls.Add(ImageDiv);
            }

            return(PostDiv);
        }