November Happy Hour will be moved to Thursday December 5th.
AI OnAI Off
November Happy Hour will be moved to Thursday December 5th.
I haven't found a solution (not sure whether it's possible to get comments sorted by email/status), but I did found a work-around: get all the comments, then filter out the comments you don't want, and then order the List of comments. Here is the code:
var query = new EntryCommentQuery();
var col = QueryHandler.Instance.GetQueryResult<EntryComment, EntryCommentCollection>(query)
.Select(c => new CommunityComment(c));
// filter for the current site's languages
var comments = col.Where(
c => (languageBranch == null || languageBranch == c.LanguageBranch) &&
(startDate == null || c.Created > startDate) &&
(
(getApproved && c.Status == CommunityCommentStatus.Approved) ||
(getAbuse && c.Status == CommunityCommentStatus.AbuseReported) ||
(getWaiting && c.Status == CommunityCommentStatus.WaitingApproval) ||
(getSpamSuspected && c.Status == CommunityCommentStatus.SpamSuspected) ||
(getMatchPhrases && new CommentPhrasesMatcher(c.Content).Match(false))
)
);
int sortDirection = (int)(ViewState["SortDirection"] ?? 1);
string sortField = (string)ViewState["SortField"] ?? "Created";
switch (sortField)
{
case "Status":
comments = comments.OrderBy(c => sortDirection * (int)c.Status).ToList();
break;
case "Email":
comments = comments.OrderBy(c => c.Author, new AuthorEmailComparer(sortDirection)).ToList();
break;
case "Created":
default:
comments = comments.OrderBy(c => sortDirection * -c.Created.Ticks).ToList();
break;
}
Hi,
I want to collect BlogEntries-comments. I want to use paging and sorting in order to display them correctly.
Paging works fine. And sorting on Created also works. But apparently, the EntryCommentQuery does not support ordering on Email and/or Status? I can order the comments with LINQ after I got a subset of comments, but then the ordering isn't working correctly.
So, how can I get the comments, sorted on email / status? Here is my code so far:
Best, Leonard