Пример #1
0
        public static IAsyncDocumentQuery <TSource> Sort <TSource>(this IAsyncDocumentQuery <TSource> source, HttpRequestMessage request)
        {
            var descending = true;

            var direction = request.GetQueryStringValue("direction", "desc");

            if (direction == "asc")
            {
                descending = false;
            }

            string keySelector;

            var sort = request.GetQueryStringValue("sort", "time_sent");

            if (!AsyncDocumentQuerySortOptions.Contains(sort))
            {
                sort = "time_sent";
            }

            switch (sort)
            {
            case "id":
            case "message_id":
                keySelector = "MessageId";
                break;

            case "message_type":
                keySelector = "MessageType";
                break;

            case "status":
                keySelector = "Status";
                break;

            case "modified":
                keySelector = "LastModified";
                break;

            case "time_of_failure":
                keySelector = "TimeOfFailure";
                break;

            default:
                keySelector = "TimeSent";
                break;
            }

            return(source.AddOrder(keySelector, descending));
        }
        public static IAsyncDocumentQuery <TSource> Sort <TSource>(this IAsyncDocumentQuery <TSource> source, Request request)
        {
            var direction  = "desc";
            var descending = true;

            if (request.Query.direction.HasValue)
            {
                direction = (string)request.Query.direction;
            }

            if (direction == "asc")
            {
                descending = false;
            }

            var sortOptions = new[]
            {
                "id", "message_id", "message_type",
                "time_sent", "status", "modified", "time_of_failure"
            };

            var    sort = "time_sent";
            string keySelector;

            if (request.Query.sort.HasValue)
            {
                sort = (string)request.Query.sort;
            }

            if (!sortOptions.Contains(sort))
            {
                sort = "time_sent";
            }

            switch (sort)
            {
            case "id":
            case "message_id":
                keySelector = "MessageId";
                break;

            case "message_type":
                keySelector = "MessageType";
                break;

            case "status":
                keySelector = "Status";
                break;

            case "modified":
                keySelector = "LastModified";
                break;

            case "time_of_failure":
                keySelector = "TimeOfFailure";
                break;

            default:
                keySelector = "TimeSent";
                break;
            }

            return(source.AddOrder(keySelector, descending));
        }