Problem in understanding EnsureValidSortExp syntax
protected virtual string EnsureValidSortExpression(string sortExpression)
{
if (string.IsNullOrEmpty(sortExpression))
return "LastPostDate DESC";
string sortExpr = sortExpression.ToLower();
if (!sortExpr.Equals("lastpostdate") && !sortExpr.Equals("lastpostdate asc") &&
!sortExpr.Equals("lastpostdate desc") && !sortExpr.Equals("viewcount") &&
!sortExpr.Equals("viewcount asc") && !sortExpr.Equals("viewcount desc") &&
!sortExpr.Equals("replycount") && !sortExpr.Equals("replycount asc") &&
!sortExpr.Equals("replycount desc") && !sortExpr.Equals("addeddate") &&
!sortExpr.Equals("addeddate asc") && !sortExpr.Equals("addeddate desc") &&
!sortExpr.Equals("addedby") && !sortExpr.Equals("addedby asc") &&
!sortExpr.Equals("addedby desc") && !sortExpr.Equals("title") &&
!sortExpr.Equals("title asc") && !sortExpr.Equals("title desc") &&
!sortExpr.Equals("lastpostby") && !sortExpr.Equals("lastpostby asc") &&
!sortExpr.Equals("lastpostby desc"))
{
return "LastPostDate DESC";
}
else
{
if (sortExpr.StartsWith("title"))
sortExpr = sortExpr.Replace("title", "tbh_posts.title");
if (!sortExpr.StartsWith("lastpostdate"))
sortExpr += ", LastPostDate DESC";
return sortExpr;
}
}
i have to ask two questions...
First, In the else part why this sort expression title or
title desc or title asc is converted into tbh_posts.title while this LastPostDate or LastPostDate DESC LastPostDate DESC is not converted into tbh_posts.lastpostdate. Except the sort expression containing title, none other sortexpression is convert into the string like tbh_post_columnname (even in case of null LastPostDate DESC is returned). sortExpression contains column name of post table then, why we just do this conversion in case of title.
Second, What is meant by this last check
if (!sortExpr.StartsWith("lastpostdate"))
sortExpr += ", LastPostDate DESC";
if sortExpression start this lastpostdate convert it into
sortExpression = sortExpression + , LastPostDate DESC;
sortexpression will become lastpostdate,LastPostDate DESC
or lastpostdate ASC,LastPostDate DESC
or lastpostdate DESC,LastPostDate DESC
now what is this and it will be true in wut conditions?
-Thanks in advance!
|