Ejemplo n.º 1
0
        /// <summary>
        /// GetPostByID returns a post with the approved comment count.
        /// </summary>
        public Post GetPostById(int postId)
        {
            Collection <Post> posts = new Collection <Post>();

            using (SqlConnection connection = this.GetConnection())
            {
                connection.Open();

                SqlCommand sc = new SqlCommand();

                sc.CommandText = "GetPostById";

                sc.Parameters.AddWithValue("PostId", postId);

                sc.CommandType = CommandType.StoredProcedure;
                sc.Connection  = connection;

                using (SqlDataReader reader = sc.ExecuteReader())
                {
                    posts = SqlDataMap.CreatePostsFromReader(reader);
                }
            }

            if (posts.Count > 0)
            {
                return(posts[0]);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 2
0
        public Category GetCategoryById(int categoryId)
        {
            Collection <Category> cats;

            using (SqlConnection connection = this.GetConnection())
            {
                connection.Open();
                SqlCommand sc = new SqlCommand("GetCategoryById", connection);

                sc.CommandType = CommandType.StoredProcedure;
                sc.Parameters.AddWithValue("CategoryId", categoryId);

                using (SqlDataReader reader = sc.ExecuteReader())
                {
                    cats = SqlDataMap.CreateCategoriesFromReader(reader);
                }
            }

            if (cats.Count > 0)
            {
                return(cats[0]);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 3
0
        public Collection <Comment> GetAllComments(CommentType ctype)
        {
            using (SqlConnection connection = this.GetConnection())
            {
                connection.Open();

                SqlCommand sc = new SqlCommand("GetAllComments", connection);
                sc.CommandType = CommandType.StoredProcedure;

                Collection <Comment> clist = SqlDataMap.CreateCommentsFromReader(sc.ExecuteReader());

                return(clist);
            }
        }
Ejemplo n.º 4
0
        public Collection <Category> GetAllCategories()
        {
            Collection <Category> cats;

            using (SqlConnection connection = this.GetConnection())
            {
                connection.Open();
                SqlCommand sc = new SqlCommand("GetAllCategories", connection);

                sc.CommandType = CommandType.StoredProcedure;
                using (SqlDataReader reader = sc.ExecuteReader())
                {
                    cats = SqlDataMap.CreateCategoriesFromReader(reader);
                }
            }

            return(cats);
        }
Ejemplo n.º 5
0
        public Collection <Post> GetAllPosts(int categoryId, DateTime startDate, DateTime endDate, CommentType ctype, int numberOfPosts)
        {
            //// int numberOfPosts = 10;
            Collection <Post> posts = new Collection <Post>();

            using (SqlConnection connection = this.GetConnection())
            {
                connection.Open();

                SqlCommand sc = new SqlCommand();

                sc.CommandText = "GetAllPosts";

                sc.Parameters.AddWithValue("NumberOfPosts", numberOfPosts);
                sc.Parameters.AddWithValue("CategoryId", categoryId);
                sc.Parameters.AddWithValue("DateFrom", startDate);
                sc.Parameters.AddWithValue("DateTo", endDate);

                if (ctype != CommentType.All)
                {
                    sc.Parameters.AddWithValue("@ApprovedCommentsOnly", ctype == CommentType.Approved ? 1 : 0);
                }
                else
                {
                    sc.Parameters.AddWithValue("@ApprovedCommentsOnly", DBNull.Value);
                }

                sc.CommandType = CommandType.StoredProcedure;
                sc.Connection  = connection;

                using (SqlDataReader reader = sc.ExecuteReader())
                {
                    posts = SqlDataMap.CreatePostsFromReader(reader);
                }
            }

            return(posts);
        }
Ejemplo n.º 6
0
        public Collection <Comment> GetCommentsForPost(int postId, CommentType ctype)
        {
            using (SqlConnection connection = this.GetConnection())
            {
                connection.Open();

                SqlCommand sc = new SqlCommand("GetCommentsByPost", connection);
                sc.CommandType = CommandType.StoredProcedure;

                sc.Parameters.AddWithValue("PostId", postId);

                if (ctype == CommentType.All)
                {
                    sc.Parameters.AddWithValue("Approved", DBNull.Value);
                }
                else
                {
                    int bitValue = 0;

                    if (ctype == CommentType.Approved)
                    {
                        bitValue = 1;
                    }
                    else if (ctype == CommentType.UnApproved)
                    {
                        bitValue = 0;
                    }

                    sc.Parameters.AddWithValue("Approved", bitValue);
                }

                Collection <Comment> clist = SqlDataMap.CreateCommentsFromReader(sc.ExecuteReader());

                return(clist);
            }
        }