Exemplo n.º 1
0
        public static void MaybeEnvelope <T>(this HttpResponse response, HttpRequest request,
                                             JsonConversionOptions options, IPage <T> data, IList <Error> errors, out object body)
        {
            var provider = request.HttpContext.RequestServices.GetService <IPagingInfoProvider>();

            if (FeatureRequested(request, options.EnvelopeOperator))
            {
                var envelope = new EnvelopeCollectionBody <T>
                {
                    Data      = data,
                    Status    = response.StatusCode,
                    Headers   = response.Headers,
                    Errors    = errors,
                    HasErrors = errors?.Count > 0
                };

                body = envelope;

                if (provider != null)
                {
                    envelope.Paging = provider.GetPagingInfo(request, data);
                }

                response.StatusCode = (int)HttpStatusCode.OK;
                return;
            }

            provider?.SetPagingInfoHeaders(request, response, data);

            body = new NestedCollectionBody <T> {
                Data = data, Errors = errors, HasErrors = errors?.Count > 0
            };
        }
Exemplo n.º 2
0
        public static void MaybeEnvelope <T>(this HttpResponse response, HttpRequest request,
                                             JsonConversionOptions options, IStream <T> data, IList <Error> errors, out object body)
        {
            if (FeatureRequested(request, options.EnvelopeOperator))
            {
                body = new EnvelopeCollectionBody <T>
                {
                    Data      = data,
                    Status    = response.StatusCode,
                    Headers   = response.Headers,
                    Errors    = errors,
                    HasErrors = errors?.Count > 0
                };
            }
            else
            {
                body = new NestedCollectionBody <T> {
                    Data = data, Errors = errors, HasErrors = errors?.Count > 0
                };
            }

            response.StatusCode = (int)HttpStatusCode.OK;
        }