private void GetComments(XmlTextWriter writer) { CommentFilter filter = CommentFilter.FromQueryString(Request.QueryString); Query q = filter.ToQuery(); q.AndWhere(Comment.Columns.IsDeleted, false); CommentCollection comments = new CommentCollection(); comments.LoadAndCloseReader(q.ExecuteReader()); writer.WriteStartElement("comments"); writer.WriteAttributeString("pageIndex", q.PageIndex.ToString()); writer.WriteAttributeString("pageSize", q.PageSize.ToString()); writer.WriteAttributeString("totalComments", q.GetRecordCount().ToString()); foreach (Comment coment in comments) { ConvertComentToXML(coment, writer); } writer.WriteEndElement(); }
// parse querystring into filter public static CommentFilter FromQueryString(NameValueCollection queryString) { CommentFilter postFilter = new CommentFilter(); 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 postId; string cid = queryString[QueryStringKey.PostId]; if ((!string.IsNullOrEmpty(cid)) && (int.TryParse(cid, out postId))) { postFilter.PostId = postId; } string sc = queryString[QueryStringKey.Spam]; if (sc != null) { postFilter.SpamScore = Int32.Parse(sc); } postFilter.IPAddress = queryString[QueryStringKey.IPAddress]; postFilter.Name = queryString[QueryStringKey.Name]; // 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; } bool isPublished = false; string ip = queryString[QueryStringKey.IsPublished]; if ((!string.IsNullOrEmpty(ip)) && (bool.TryParse(ip, out isPublished))) { postFilter.IsPublished = isPublished ? 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; } return(postFilter); }
// parse querystring into filter public static CommentFilter FromQueryString(NameValueCollection queryString) { CommentFilter postFilter = new CommentFilter(); 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 postId; string cid = queryString[QueryStringKey.PostId]; if ((!string.IsNullOrEmpty(cid)) && (int.TryParse(cid, out postId))) postFilter.PostId = postId; string sc = queryString[QueryStringKey.Spam]; if (sc != null) postFilter.SpamScore = Int32.Parse(sc); postFilter.IPAddress = queryString[QueryStringKey.IPAddress]; postFilter.Name = queryString[QueryStringKey.Name]; // 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; bool isPublished = false; string ip = queryString[QueryStringKey.IsPublished]; if ((!string.IsNullOrEmpty(ip)) && (bool.TryParse(ip, out isPublished))) postFilter.IsPublished = isPublished ? 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; return postFilter; }