/// <summary> /// Validates orderby string and constructs SortInformation object. If not valid returns null. /// </summary> /// <param name="orderBy"></param> /// <param name="validOrderByOptions"></param> /// <returns>If order is not valid null, otherwise insatnce of <see cref="SortInformation"/></returns> protected SortInformation ParseOrderBy(string orderBy, string validOrderByOptions) { if (string.IsNullOrWhiteSpace(orderBy)) { return(null); } SortInformation sortInformation = GetSortInformation(orderBy); if (validOrderByOptions.Contains(sortInformation.PropertyName)) { return(sortInformation); } return(null); }
private SortInformation GetSortInformation(string orderby) { SortInformation sortInformation; if (orderby.StartsWith("-")) { sortInformation = new SortInformation { PropertyName = orderby.Substring(1, orderby.Length - 1), SortDirection = ListSortDirection.Descending }; } else { sortInformation = new SortInformation { PropertyName = orderby, SortDirection = ListSortDirection.Ascending }; } return(sortInformation); }