Example #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                PostManager postManager=new PostManager();
                CommentManager anCommentManager=new CommentManager();
                List<Post> last5Posts = postManager.GetLast5Post();
                string allPosts = "";
                string oneLine = "";
                User aUser = (User) Session["aUser"];
                //List<Post> homePosts=(List<Post>) last5Posts.Take(5);
                foreach (Post anResultPost in last5Posts)
                {
                    if (anResultPost.PostDescreption.Length > 200)
                    {
                        oneLine = anResultPost.PostDescreption.Substring(0, 200);
                    }
                    else
                    {
                        oneLine = anResultPost.PostDescreption;
                    }
                    int commentCount = anCommentManager.GetCommentCount(anResultPost.PostId);
                    string edit="";
                    if (aUser != null && aUser.UserId == anResultPost.userId)
                    {
                        edit = "<a href='submit-post.aspx?id=" + anResultPost.PostId + "'>  Edit</a>";
                    }
                    allPosts += "<div class='post_section'><div class='post_date'><span>" + anResultPost.PostCreatedDate + "</span></div> <div class='post_content'><h2><a href='single-post.aspx?id=" + anResultPost.PostId + "'>" + anResultPost.PostTitle + "</a></h2> <strong>  Author:</strong> <a href='author-profile.aspx?id=" + anResultPost.userId + "'>" + anResultPost.UserFullName + "</a>  <strong>  Post View:  </strong>" + anResultPost.ViewCount + "<strong>  Comment:" + commentCount + "  </strong> " + edit + " <div> " + oneLine + "  <a href='single-post.aspx?id=" + anResultPost.PostId + "'>Read More</a></div></div> <div class='cleaner'></div></div>";

                }
                allpost.InnerHtml = allPosts;

                List<Post> popularPosts = postManager.GetPopularPost();

                string subDescription = "";
                string mostpopularpost = "";
                foreach (Post anPopularPost in popularPosts)
                {
                    if (anPopularPost.PostDescreption.Length > 200)
                    {
                        subDescription = anPopularPost.PostDescreption.Substring(0, 200);
                    }
                    else
                    {
                        subDescription = anPopularPost.PostDescreption;
                    }
                    string edit="";
                    if (aUser != null && aUser.UserId == anPopularPost.userId)
                    {
                        edit = "<a href='submit-post.aspx?id=" + anPopularPost.PostId + "'>  Edit Post</a>";
                    }
                    mostpopularpost += "<li><h6><a href='single-post.aspx?id=" + anPopularPost.PostId + "'>" + anPopularPost.PostTitle + "</a></h6><div><strong>Author: </strong><a href='author-profile.aspx?id=" + anPopularPost.userId + "'>" + anPopularPost.UserFullName + "</a><strong>  view: </strong> " + anPopularPost.ViewCount + "" + edit + " </div><p>" + subDescription + "  <a href='single-post.aspx?id=" + anPopularPost.PostId + "'>Read More</a> </p></li>";

                }

                popularpost.InnerHtml = mostpopularpost;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            User anUser = (User)Session["aUser"];
            if (anUser != null)
            {
              //  userNameLabel.InnerText = anUser.UserFullName;

                string allPosts = "";
                string oneLine = "";

                PostManager aPostManager = new PostManager();
                CommentManager anCommentManager=new CommentManager();

                List<Post> aPostList = aPostManager.GetUserData(anUser.UserId);

                foreach (Post anResultPost in aPostList)
                {

                    if (anResultPost.PostDescreption.Length > 200)
                    {
                        oneLine = anResultPost.PostDescreption.Substring(0, 200);
                    }
                    else
                    {
                        oneLine = anResultPost.PostDescreption;
                    }
                    string isPublished;
                    if (anResultPost.PostIsPublished)
                    {
                        isPublished = "Published";
                    }
                    else
                    {
                        isPublished = "Unpublished";
                    }
                    int commentCount = anCommentManager.GetCommentCount(anResultPost.PostId);
                    allPosts += "<div class='post_section'><div class='post_date'><span>" + anResultPost.PostCreatedDate + "</span></div> <div class='post_content'><h2><a href='single-post.aspx?id=" + anResultPost.PostId + "'>" + anResultPost.PostTitle + "</a></h2> <strong>Author:</strong> " + anResultPost.UserFullName + "  <strong>Post View:  </strong>" + anResultPost.ViewCount + " <strong>Post Status:" + isPublished + "  </strong><strong>  Comment:" + commentCount + "  </strong><strong>  <a href='submit-post.aspx?id=" + anResultPost.PostId + "'>  Edit</a> </strong> <div> " + oneLine + "  <a href='single-post.aspx?id=" + anResultPost.PostId + "'>Read More</a></div></div> <div class='cleaner'></div></div>";
                }
                userPost.InnerHtml = allPosts;

            }

            else
            {
                Response.Redirect("LoginPage.aspx");
            }

            //authorLabel.Text = anUser.UserFullName;

            //GetUserData(anUser.UserId);
        }
Example #3
0
        protected void submit_Click(object sender, EventArgs e)
        {
            User aUser = (User)Session["aUser"];

            if (aUser != null)
            {
               Comment anComment=new Comment();

                anComment.PostId = Convert.ToInt32(Request.QueryString["id"]);
                anComment.UserId = aUser.UserId;
                anComment.CommentDescreption = commentText.InnerText;

                CommentManager anCommentManager=new CommentManager();
                anCommentManager.InsertComment(anComment);
                commentText.InnerText = "";

            }
            else
            {
                Response.Redirect("LoginPage.aspx");
            }
        }