Example #1
0
        public BlogModel GetBlog(string strId, bool bGUID = false)
        {
            BlogModel blog = new BlogModel();

            SqlCommand cmd;

            if (bGUID)
            {
                cmd = new SqlCommand(@"select * from blog where id=@id");
            }
            else
            {
                cmd = new SqlCommand(@"select * from blog where url=@id");
            }
            if (strId != null)
            {
                cmd.Parameters.AddWithValue("@id", strId);
            }
            else
            {
                cmd.Parameters.AddWithValue("@id", DBNull.Value);
            }
            XElement nd = db.ExecQueryElem(cmd, "Blog");

            if (nd != null)
            {
                blog.SerializeFromXml(nd);
            }
            return(blog);
        }
Example #2
0
        public List <BlogModel> GetBlogs(string strBlogTypeID = null)
        {
            List <BlogModel> blogs = new List <BlogModel>();
            SqlCommand       cmd   = new SqlCommand();

            string strCommand = @"select b.*, t.name as blogtype from blog b
left join blogtype t on t.id=b.blogtypeid
where b.deleted is null ";

            if (strBlogTypeID != null)
            {
                strCommand += " and b,blogtypeid=@id";
                cmd.Parameters.AddWithValue("@blogtypeid", strBlogTypeID);
            }
            cmd.CommandText = strCommand;
            XDocument xmlBlog = db.ExecQuery(cmd, "Blog");

            foreach (XElement nd in xmlBlog.Descendants("Blog"))
            {
                BlogModel blog = new BlogModel();
                blog.SerializeFromXml(nd);
                blogs.Add(blog);
            }

            return(blogs);
        }