private void bindBlogPosts(BlogPost[] blogPosts) { dgPendingApproval.Columns[0].HeaderText = Lang.TransA("Username"); dgPendingApproval.Columns[1].HeaderText = Lang.TransA("Title"); dgPendingApproval.Columns[2].HeaderText = Lang.TransA("Content"); DataTable dtAnswers = new DataTable("BlogPosts"); dtAnswers.Columns.Add("ID"); dtAnswers.Columns.Add("Username"); dtAnswers.Columns.Add("Title"); dtAnswers.Columns.Add("Content"); dtAnswers.Columns.Add("DatePosted"); foreach (BlogPost blogPost in blogPosts) { Blog blog = Blog.Load(blogPost.BlogId); if (blog == null) continue; dtAnswers.Rows.Add(new object[] { blogPost.Id, blog.Username, blogPost.Title, blogPost.Content.Length > 300 ? Server.HtmlEncode(blogPost.Content.Substring(0, 300)) + "..." : Server.HtmlEncode(blogPost.Content), blogPost.DatePosted } ); } dgPendingApproval.DataSource = dtAnswers; try { dgPendingApproval.DataBind(); } catch (HttpException) { dgPendingApproval.CurrentPageIndex = 0; dgPendingApproval.DataBind(); } }
private static BlogPost[] Fetch(int blogId, int blogPostId, bool? approved) { List<BlogPost> lBlogPosts = new List<BlogPost>(); using (SqlConnection conn = Config.DB.Open()) { SqlDataReader reader = SqlHelper.ExecuteReader(conn, "FetchBlogPosts", blogId, blogPostId, approved); while (reader.Read()) { BlogPost blogPost = new BlogPost(); blogPost.id = (int) reader["Id"]; blogPost.blogId = (int) reader["BlogId"]; blogPost.title = (string) reader["Title"]; blogPost.content = (string) reader["Content"]; blogPost.datePosted = (DateTime) reader["DatePosted"]; blogPost.reads = (int) reader["Reads"]; blogPost.approved = (bool) reader["Approved"]; lBlogPosts.Add(blogPost); } } return lBlogPosts.ToArray(); }
public static BlogPost Create(int blogId, string title, string content) { BlogPost blogPost = new BlogPost(); blogPost.id = -1; blogPost.blogId = blogId; blogPost.title = title; blogPost.content = content; blogPost.datePosted = DateTime.Now; blogPost.reads = 0; return blogPost; }
private void LoadBlogPost(BlogPost blogPost) { lblDate.Text = blogPost.DatePosted.ToLongDateString(); lblTitle.Text = Server.HtmlEncode(blogPost.Title); lblContent.Text = stripDangerousHtml(blogPost.Content); lblDirectLink.Text = UrlRewrite.CreateShowUserBlogUrl(CurrentBlog.Username, BlogPostId); divViewPost.Visible = true; divViewBlog.Visible = false; }