protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                User aUser = (User)Session["aUser"];
                string id = Request.QueryString["id"];
                PostManager anPostManager=new PostManager();
                Post anPost= anPostManager.GetPostById(id);
                string edit="";
                postitle.InnerHtml = anPost.PostTitle;
                if (aUser!=null && aUser.UserId==anPost.userId)
                {
                    edit = "<a href='submit-post.aspx?id=" + anPost.PostId + "'>  Edit</a>";
                }
                string postdes = "<strong>Author:</strong><a href='author-profile.aspx?id=" + anPost.userId + "'>" + anPost.UserFullName + "</a>|<strong>Post View: </strong>" + anPost.ViewCount + " " + edit + "  <p>" + anPost.PostDescreption + "</p>";

                postcontent.InnerHtml = postdes;
                if (Session["aUser"] != null)
                {

                    Login1.Visible = false;
                    login.InnerText = "Hi " + aUser.UserFullName;
                }

            }
        }
Beispiel #2
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);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Model.User anUser = (User) Session["aUser"];
                string queryst = Request.QueryString["id"];
                if (anUser == null)
                {
                    Response.Redirect("LoginPage.aspx");
                }
                else if (queryst != null)
                {
                    PostManager anPostManager = new PostManager();
                    Post aPost = anPostManager.GetPostById(queryst);

                    if (aPost.userId == anUser.UserId)
                    {
                        titleTexbox.Text = aPost.PostTitle;
                        edit.InnerText = aPost.PostDescreption;
                        if (aPost.PostIsPublished)
                        {
                            DropDownList1.SelectedItem.Text = "Published";
                            DropDownList1.SelectedItem.Value = "True";
                        }
                        else
                        {
                            DropDownList1.SelectedItem.Text = "UnPublished";
                            DropDownList1.SelectedItem.Value = "false";
                        }

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

                }

            }
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            string queryst= Request.QueryString["id"];
            if (queryst != null)
            {
                PostManager anPostManager=new PostManager();
                Post anPost=new Post();
                anPost.PostId = Convert.ToInt32(queryst);
                anPost.PostTitle = titleTexbox.Text;
                anPost.PostDescreption = edit.InnerText;
                if (DropDownList1.SelectedValue == "true")
                {
                    anPost.PostIsPublished = true;
                }
                else
                {
                    anPost.PostIsPublished = false;
                }

                Model.User anUser = (User)Session["aUser"];

                anPost.userId = anUser.UserId;

                if (anPost.PostTitle != "" && anPost.PostDescreption != "")
                {
                    if (anPostManager.UpdatePostById(anPost) > 0)
                    {
                        Response.Redirect("UserControlPanel.aspx");

                    }
                }
                else
                {
                    msg.InnerText = "Please Enter Both title and Description";
                }

            }
            else
            {
                PostManager anPostManager=new PostManager();
                Post anPost=new Post();
                anPost.PostTitle = titleTexbox.Text;
                anPost.PostDescreption = edit.Value;
                if (DropDownList1.SelectedValue == "true")
                {
                    anPost.PostIsPublished = true;
                }
                else
                {
                    anPost.PostIsPublished = false;
                }

                Model.User anUser = (User)Session["aUser"];

                anPost.userId = anUser.UserId;
              if (anPost.PostTitle != "" && anPost.PostDescreption != "")
                {
                if (anPostManager.InsertPost(anPost) > 0)
                {
                    Response.Redirect("UserControlPanel.aspx");

                }
                }
              else
              {
              msg.InnerText = "Please Enter Both title and Description";
              }

            }
        }