예제 #1
0
        private void GetPosts(XmlTextWriter writer)
        {
            PostFilter filter = PostFilter.FromQueryString(Request.QueryString);
            Query      q      = filter.ToQuery();

            q.AndWhere(Post.Columns.IsDeleted, false);

            PostCollection posts = PostCollection.FetchByQuery(q);

            writer.WriteStartElement("posts");
            writer.WriteAttributeString("pageIndex", q.PageIndex.ToString());
            writer.WriteAttributeString("pageSize", q.PageSize.ToString());
            writer.WriteAttributeString("totalPosts", q.GetRecordCount().ToString());
            foreach (Post post in posts)
            {
                ConvertPostToXML(post, writer);
            }

            writer.WriteEndElement();
        }
예제 #2
0
        // parse querystring into filter
        public static PostFilter FromQueryString(NameValueCollection queryString)
        {
            PostFilter postFilter = new PostFilter();

            string id = queryString[QueryStringKey.Id];

            if (!string.IsNullOrEmpty(id))
            {
                postFilter.Id = Int32.Parse(id);
                return(postFilter);
            }

            // parse and set author filter
            string author = queryString[QueryStringKey.Author];

            if (!string.IsNullOrEmpty(author))
            {
                postFilter.Author = author;
            }

            // parse and set category filter
            int    categoryId;
            string cid = queryString[QueryStringKey.CategoryId];

            if ((!string.IsNullOrEmpty(cid)) && (int.TryParse(cid, out categoryId)))
            {
                postFilter.CategoryId = categoryId;
            }

            if (postFilter.CategoryId > 0)
            {
                postFilter.IncludeChildCategories =
                    Util.AreEqualIgnoreCase(queryString[QueryStringKey.IncludeChildCategories], "true");
            }

            // parse and set status filter
            string s = queryString[QueryStringKey.Status];

            if (!string.IsNullOrEmpty(s))
            {
                PostStatus status = PostStatus.NotSet;
                try { status = (PostStatus)Enum.Parse(typeof(PostStatus), s, true); }
                catch { }
                postFilter.Status = status;
            }

            // parse and set deleted filter
            bool   isDeleted = false;
            string d         = queryString[QueryStringKey.IsDeleted];

            if ((!string.IsNullOrEmpty(d)) && (bool.TryParse(d, out isDeleted)))
            {
                postFilter.IsDeleted = isDeleted ? TrueFalseIgnore.True : TrueFalseIgnore.False;
            }

            // parse and set page index filter
            int    pageIndex;
            string pi = queryString[QueryStringKey.PageIndex];

            if ((!string.IsNullOrEmpty(pi)) && (int.TryParse(pi, out pageIndex)))
            {
                postFilter.PageIndex = pageIndex;
            }

            // parse and set page size filter
            int    pageSize;
            string ps = queryString[QueryStringKey.PageSize];

            if ((!string.IsNullOrEmpty(ps)) && (int.TryParse(ps, out pageSize)))
            {
                postFilter.PageSize = pageSize;
            }

            int    parnetId;
            string parId = queryString[QueryStringKey.ParentId];

            if ((!string.IsNullOrEmpty(parId)) && (int.TryParse(parId, out parnetId)))
            {
                postFilter.ParentId = parnetId;
            }

            return(postFilter);
        }
예제 #3
0
        // parse querystring into filter
        public static PostFilter FromQueryString(NameValueCollection queryString)
        {
            PostFilter postFilter = new PostFilter();

            string id = queryString[QueryStringKey.Id];
            if(!string.IsNullOrEmpty(id))
            {
                postFilter.Id = Int32.Parse(id);
                return postFilter;
            }

            // parse and set author filter
            string author = queryString[QueryStringKey.Author];
            if (!string.IsNullOrEmpty(author))
                postFilter.Author = author;

            // parse and set category filter
            int categoryId;
            string cid = queryString[QueryStringKey.CategoryId];
            if ((!string.IsNullOrEmpty(cid)) && (int.TryParse(cid, out categoryId)))
                postFilter.CategoryId = categoryId;

            if(postFilter.CategoryId > 0)
            {
                postFilter.IncludeChildCategories =
                    Util.AreEqualIgnoreCase(queryString[QueryStringKey.IncludeChildCategories], "true");
            }

            // parse and set status filter
            string s = queryString[QueryStringKey.Status];
            if (!string.IsNullOrEmpty(s))
            {
                PostStatus status = PostStatus.NotSet;
                try { status = (PostStatus)Enum.Parse(typeof(PostStatus), s, true); }
                catch { }
                postFilter.Status = status;
            }

            // parse and set deleted filter
            bool isDeleted = false;
            string d = queryString[QueryStringKey.IsDeleted];
            if ((!string.IsNullOrEmpty(d)) && (bool.TryParse(d, out isDeleted)))
                postFilter.IsDeleted = isDeleted ? TrueFalseIgnore.True : TrueFalseIgnore.False;

            // parse and set page index filter
            int pageIndex;
            string pi = queryString[QueryStringKey.PageIndex];
            if ((!string.IsNullOrEmpty(pi)) && (int.TryParse(pi, out pageIndex)))
                postFilter.PageIndex = pageIndex;

            // parse and set page size filter
            int pageSize;
            string ps = queryString[QueryStringKey.PageSize];
            if ((!string.IsNullOrEmpty(ps)) && (int.TryParse(ps, out pageSize)))
                postFilter.PageSize = pageSize;

            int parnetId;
            string parId = queryString[QueryStringKey.ParentId];
            if ((!string.IsNullOrEmpty(parId)) && (int.TryParse(parId, out parnetId)))
                postFilter.ParentId = parnetId;

            return postFilter;
        }