Beispiel #1
0
        private static BlogPost[] Fetch(int blogId, int blogPostId, bool? approved)
        {
            List<BlogPost> lBlogPosts = new List<BlogPost>();

            using (SqlConnection conn = Config.DB.Open())
            {
                SqlDataReader reader = (SqlDataReader) SqlHelper.GetDB().ExecuteReader( "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();
        }
Beispiel #2
0
 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;
 }