示例#1
0
        private IEnumerable <SortObject> GetSortObjects(IEnumerable <string> sortKeys)
        {
            var list = new List <SortObject>();

            var fields     = new List <string>();
            var directions = new List <string>();

            foreach (var sortKey in sortKeys)
            {
                if (sortKey.Contains("field"))
                {
                    fields.Add(GetQueryStringValue(sortKey).Replace("_", "."));
                }

                if (sortKey.Contains("dir"))
                {
                    directions.Add(GetQueryStringValue(sortKey));
                }
            }

            foreach (var field in fields)
            {
                var index     = fields.IndexOf(field);
                var direction = directions[index];
                var obj       = new SortObject(field, direction);
                list.Add(obj);
            }

            return(list);
        }
示例#2
0
        public static string GetSqlOrderByClause(IEnumerable <SortObject> filters, SortObject defaultFilter = null)
        {
            var orderbyClauseFilters = new List <string>();

            foreach (var sort in filters)
            {
                sort.Field = sort.Field.Replace("_", ".");
                orderbyClauseFilters.Add("{0} {1}".FormatWith(sort.Field, sort.Direction));
            }
            var orderbyClause = string.Join(", ", orderbyClauseFilters);

            if (defaultFilter != null && !filters.Any(c => c.Field.Equals(defaultFilter.Field, StringComparison.InvariantCultureIgnoreCase)))
            {
                if (orderbyClauseFilters.Count > 0)
                {
                    orderbyClause += ", ";
                }
                orderbyClause += "{0} {1}".FormatWith(defaultFilter.Field, defaultFilter.Direction);
            }

            return(orderbyClause);
        }
        private IEnumerable<SortObject> GetSortObjects(IEnumerable<string> sortKeys)
        {
            var list = new List<SortObject>();

            var fields = new List<string>();
            var directions = new List<string>();

            foreach (var sortKey in sortKeys)
            {
                if (sortKey.Contains("field"))
                    fields.Add(GetQueryStringValue(sortKey).Replace("_", "."));

                if (sortKey.Contains("dir"))
                    directions.Add(GetQueryStringValue(sortKey));
            }

            foreach (var field in fields)
            {
                var index = fields.IndexOf(field);
                var direction = directions[index];
                var obj = new SortObject(field, direction);
                list.Add(obj);
            }

            return list;
        }