Пример #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);
        }
Пример #2
0
        public override IQueryable <Contact> SetUpSorting(IQueryable <Contact> query)
        {
            SortInformation sortInformation = ParseOrderBy(OrderBy, ValidOrderByValues);

            if (sortInformation == null)
            {
                return(query);
            }

            switch (sortInformation.PropertyName)
            {
            case "name":
                query = ApplyOrdering(query, s => s.Name, sortInformation.SortDirection);
                break;

            case "address":
                query = ApplyOrdering(query, s => s.Address, sortInformation.SortDirection);
                break;
            }

            return(query);
        }
Пример #3
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);
        }