Ejemplo n.º 1
0
        public static SortingOptions Parse(string sort)
        {
            if (String.IsNullOrEmpty(sort))
            {
                return(Empty);
            }

            var sortingOptions = new SortingOptions();
            var fields         = sort.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

            foreach (var field in fields)
            {
                string name  = field;
                var    order = SortOrder.Ascending;
                if (name.StartsWith("-"))
                {
                    name  = name.Substring(1);
                    order = SortOrder.Descending;
                }
                sortingOptions.Fields.Add(new FieldSort {
                    Field = name, Order = order
                });
            }

            return(sortingOptions);
        }
Ejemplo n.º 2
0
        public static SortingOptions WithField(this SortingOptions options, string field, SortOrder sort = SortOrder.Ascending)
        {
            var fieldSort = options.Fields.FirstOrDefault(f => f.Field.Equals(field, StringComparison.OrdinalIgnoreCase));

            if (fieldSort == null)
            {
                fieldSort = new FieldSort {
                    Field = field, Order = sort
                };
                options.Fields.Add(fieldSort);
            }

            fieldSort.Order = sort;

            return(options);
        }
Ejemplo n.º 3
0
        public static SortingOptions Parse(string sort) {
            if (String.IsNullOrEmpty(sort))
                return Empty;

            var sortingOptions = new SortingOptions();
            var fields = sort.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            foreach (var field in fields) {
                string name = field;
                var order = SortOrder.Ascending;
                if (name.StartsWith("-")) {
                    name = name.Substring(1);
                    order = SortOrder.Descending;
                }
                sortingOptions.Fields.Add(new FieldSort { Field = name, Order = order });
            }

            return sortingOptions;
        }