Example #1
0
        public void SaveComment(object sender, EventArgs e)
        {
            Comment c = new Comment();

            c.Url    = editcomment.URL;
            c.Name   = editcomment.Name;
            c.PostId = Post.GetPostIdFromQueryString(Request.QueryString);
            c.Text   = editcomment.Text;
            c.Posted = DateTime.Now;

            if (String.IsNullOrEmpty(c.Text))
            {
                return;
            }

            c.Save();

            ////if (chkRememberDetails.Checked)
            ////{

            ////    HttpCookie details = new HttpCookie("userDetails");
            ////    details.Values.Add("Name", c.Name);
            ////    details.Values.Add("URL", c.Url);
            ////    Response.Cookies.Add(details);
            ////}
            ////else
            ////{
            ////    if (Request.Cookies["userDetails"] != null)
            ////    {
            ////        HttpCookie details = new HttpCookie("userDetails");
            ////        details.Values.Add("Name", String.Empty);
            ////        details.Values.Add("URL", String.Empty);
            ////        Response.Cookies.Add(details);
            ////    }
            ////}

            editcomment.ClearValues();

            if (Request.Url.Fragment != "#comments")
            {
                Response.Redirect(Request.Url + "#comments");
            }

            this.GetPosts();
        }
Example #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);
                }
            }
        }