예제 #1
0
        private void GetPosts()
        {
            Collection <Post> posts;
            bool singlePost = false;

            // A request for a specific post overrides all other parameters
            int postId = this.IsQueryForSpecificPost();

            if (postId != 0)
            {
                Post post = Post.GetPostById(postId);
                posts = new Collection <Post>();
                posts.Add(post);
                singlePost = true;

                ////if (Request.Cookies["userDetails"] != null)
                ////{
                ////    editcomment.Name = Server.HtmlEncode(Request.Cookies["userDetails"]["Name"]);
                ////    editcomment.URL = Server.HtmlEncode(Request.Cookies["userDetails"]["URL"]);
                ////    chkRememberDetails.Checked = true;
                ////}
            }
            else
            {
                int      categoryId = this.GetCategoryFromQueryString();
                DateTime dateFrom, dateTo;
                this.GetDateRangeFromQueryString(out dateFrom, out dateTo);

                posts = Post.GetAllPosts(categoryId, dateFrom, dateTo, CommentType.Approved);
            }

            if (singlePost == false)
            {
                comments_inner.Style.Add("Display", "None");
            }
            else if (posts.Count != 0)
            {
                this.GetCommentsForPost(postId);
            }

            Collection <Category> catlist = Category.GetAllCategories();

            categoriesRepeater.DataSource = catlist;
            categoriesRepeater.DataBind();

            postsRepeater.DataSource = posts;
            postsRepeater.DataBind();

            this.PopulateArchive();
        }
예제 #2
0
        private void GetPost()
        {
            int postId = Post.GetPostIdFromQueryString(Request.QueryString);

            Collection <Category> allCats = Category.GetAllCategories();

            if (postId != 0)
            {
                hiddenPostId.Value = postId.ToString();

                Post p = Post.GetPostById(postId);

                if (p == null)
                {
                    editarea.Style.Add("display", "none");
                }
                else
                {
                    blogpost.Value = p.Body;
                    posttitle.Text = p.Title;
                    postslug.Text  = p.Slug;
                    DateTime postdate = p.Postdate;
                    postyear.Text      = postdate.Year.ToString();
                    postday.Text       = postdate.Day.ToString();
                    postmonth.Text     = postdate.ToString("MMMM");
                    hiddenPostId.Value = postId.ToString();

                    // Select the categories this post belongs to
                    foreach (Category cat in allCats)
                    {
                        System.Web.UI.WebControls.ListItem item = new System.Web.UI.WebControls.ListItem();
                        item.Text = cat.Name;
                        bool postInCategory = false;
                        foreach (Category c in p.Categories)
                        {
                            if (c.Id == cat.Id && c.Name == cat.Name)
                            {
                                postInCategory = true;
                                break;
                            }
                        }

                        item.Selected = postInCategory;
                        item.Value    = cat.Id.ToString();
                        CatList.Items.Add(item);
                    }
                }
            }
            else
            {
                // New post.
                postyear.Text  = DateTime.Now.Year.ToString();
                postday.Text   = DateTime.Now.Day.ToString();
                postmonth.Text = DateTime.Now.ToString("MMMM");
                slugContainer.Style.Add("Display", "None");

                foreach (Category cat in allCats)
                {
                    System.Web.UI.WebControls.ListItem item = new System.Web.UI.WebControls.ListItem();
                    item.Text  = cat.Name;
                    item.Value = cat.Id.ToString();
                    CatList.Items.Add(item);
                }
            }
        }