Beispiel #1
0
        private Task Search(string domainObject, Try <Type> doType, Try <Type> specType, Try <object> spec, HttpContext context)
        {
            if (spec.IsFailure)
            {
                return(Task.CompletedTask);
            }
            var request = context.Request;
            var response = context.Response;
            int?limit, offset;

            Utility.ParseLimitOffset(request.Query, out limit, out offset);
            var order   = request.Query.ContainsKey("order") ? request.Query["order"][0] : null;
            var count   = request.Query.ContainsKey("count") ? request.Query["count"][0] : null;
            var ordDict = Utility.ParseOrder(order);

            var additionalCommands = EmptyCommands;

            if (limit != null && Utility.IncludeCount(count, request))
            {
                additionalCommands = new[]
                {
                    new AdditionalCommand
                    {
                        Argument = new CountDomainObject.Argument <object>
                        {
                            Name = doType.Result.FullName,
                            SpecificationName = specType.Result != null ? specType.Result.FullName : null,
                            Specification     = spec.Result
                        },
                        CommandType = typeof(CountDomainObject),
                        ToHeader    = "Total-Results"
                    }
                };
            }
            return(Converter.PassThrough <SearchDomainObject, SearchDomainObject.Argument <object> >(
                       new SearchDomainObject.Argument <object>
            {
                Name = doType.Result.FullName,
                SpecificationName = specType.Result != null ? specType.Result.FullName : null,
                Specification = spec.Result,
                Limit = limit,
                Offset = offset,
                Order = ordDict
            },
                       CommandConverter.Accept(request.Headers),
                       context,
                       additionalCommands));
        }