Пример #1
0
        private void setSortOptions(HistoricActivityStatisticsQuery query, string sortOrder, string sortBy)
        {
            bool sortOptionsValid = (!string.ReferenceEquals(sortBy, null) && !string.ReferenceEquals(sortOrder, null)) || (string.ReferenceEquals(sortBy, null) && string.ReferenceEquals(sortOrder, null));

            if (!sortOptionsValid)
            {
                throw new InvalidRequestException(Status.BAD_REQUEST, "Only a single sorting parameter specified. sortBy and sortOrder required");
            }

            if (!string.ReferenceEquals(sortBy, null))
            {
                if (sortBy.Equals("activityId"))
                {
                    query.orderByActivityId();
                }
                else
                {
                    throw new InvalidRequestException(Status.BAD_REQUEST, "sortBy parameter has invalid value: " + sortBy);
                }
            }

            if (!string.ReferenceEquals(sortOrder, null))
            {
                if (sortOrder.Equals("asc"))
                {
                    query.asc();
                }
                else
                {
                    if (sortOrder.Equals("desc"))
                    {
                        query.desc();
                    }
                    else
                    {
                        throw new InvalidRequestException(Status.BAD_REQUEST, "sortOrder parameter has invalid value: " + sortOrder);
                    }
                }
            }
        }