Exemplo n.º 1
0
        /// <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);
        }
Exemplo n.º 2
0
        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);
        }