/// <summary>Initializes a new instance of <see cref="JSendRedirectResult"/>.</summary>
        /// <param name="location">The location to which to redirect.</param>
        /// <param name="controller">The controller from which to obtain the dependencies needed for execution.</param>
        public JSendRedirectResult(Uri location, ApiController controller)
        {
            if (location == null)
            {
                throw new ArgumentNullException(nameof(location));
            }

            Location = location;
            _result  = new JSendResult <SuccessResponse>(HttpStatusCode.Redirect, new SuccessResponse(), controller);
        }
        /// <summary>Initializes a new instance of <see cref="JSendCreatedResult{T}"/>.</summary>
        /// <param name="location">The location at which the content has been created.</param>
        /// <param name="content">The content value to negotiate and format in the entity body.</param>
        /// <param name="controller">The controller from which to obtain the dependencies needed for execution.</param>
        public JSendCreatedResult(Uri location, T content, ApiController controller)
        {
            if (location == null)
            {
                throw new ArgumentNullException(nameof(location));
            }

            _result = new JSendResult <SuccessResponse>(HttpStatusCode.Created, new SuccessResponse(content), controller);

            Location = location;
        }
Esempio n. 3
0
        private JSendUnauthorizedResult(IEnumerable <AuthenticationHeaderValue> challenges,
                                        JSendResult <FailResponse> .IDependencyProvider dependencies)
        {
            if (challenges == null)
            {
                throw new ArgumentNullException(nameof(challenges));
            }

            Challenges    = challenges;
            _dependencies = dependencies;
        }
Esempio n. 4
0
        /// <summary>Creates an <see cref="HttpResponseMessage"/> asynchronously.</summary>
        /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
        /// <returns>A task that, when completed, contains the <see cref="HttpResponseMessage"/>.</returns>
        public async Task <HttpResponseMessage> ExecuteAsync(CancellationToken cancellationToken)
        {
            var result = new JSendResult <FailResponse>(StatusCode, Response, Request);

            var message = await result.ExecuteAsync(cancellationToken);

            foreach (var challenge in Challenges)
            {
                message.Headers.WwwAuthenticate.Add(challenge);
            }

            return(message);
        }
        /// <summary>Initializes a new instance of <see cref="JSendBadRequestResult"/>.</summary>
        /// <param name="reason">The reason why the request could not be processed.</param>
        /// <param name="controller">The controller from which to obtain the dependencies needed for execution.</param>
        public JSendBadRequestResult(string reason, ApiController controller)
        {
            if (reason == null)
            {
                throw new ArgumentNullException(nameof(reason));
            }

            if (string.IsNullOrWhiteSpace(reason))
            {
                throw new ArgumentException(StringResources.BadRequest_WhiteSpaceReason, nameof(reason));
            }

            _result = new JSendResult <FailResponse>(HttpStatusCode.BadRequest, new FailResponse(reason), controller);
        }
Esempio n. 6
0
        /// <summary>Initializes a new instance of <see cref="JSendInvalidModelStateResult"/>.</summary>
        /// <param name="reason">
        /// The reason why the requested resource could not be found. If none is specified, a default message will be used instead.
        /// </param>
        /// <param name="controller">The controller from which to obtain the dependencies needed for execution.</param>
        public JSendNotFoundResult(string reason, ApiController controller)
        {
            if (reason == null)
            {
                reason = StringResources.NotFound_DefaultMessage;
            }

            if (string.IsNullOrWhiteSpace(reason))
            {
                throw new ArgumentException(StringResources.NotFound_WhiteSpaceReason, nameof(reason));
            }

            _result = new JSendResult <FailResponse>(HttpStatusCode.NotFound, new FailResponse(reason), controller);
        }
Esempio n. 7
0
        public JSendRedirectToRouteResult(string routeName, IDictionary <string, object> routeValues,
                                          ApiController controller)
        {
            if (routeName == null)
            {
                throw new ArgumentNullException(nameof(routeName));
            }

            RouteName   = routeName;
            RouteValues = routeValues;
            _controller = controller;

            _result = new JSendResult <SuccessResponse>(HttpStatusCode.Redirect, SuccessResponse, controller);
        }
Esempio n. 8
0
        public JSendCreatedAtRouteResult(string routeName, IDictionary <string, object> routeValues, T content,
                                         ApiController controller)
        {
            if (routeName == null)
            {
                throw new ArgumentNullException(nameof(routeName));
            }

            RouteName   = routeName;
            RouteValues = routeValues;
            _controller = controller;

            var response = new SuccessResponse(content);

            _result = new JSendResult <SuccessResponse>(StatusCode, response, controller);
        }
        /// <summary>Initializes a new instance of <see cref="JSendInvalidModelStateResult"/>.</summary>
        /// <param name="modelState">The invalid model state to include in the response's body as key-value pairs.</param>
        /// <param name="controller">The controller from which to obtain the dependencies needed for execution.</param>
        public JSendInvalidModelStateResult(ModelStateDictionary modelState, ApiController controller)
        {
            if (controller == null)
            {
                throw new ArgumentNullException(nameof(controller));
            }

            IDictionary <string, IEnumerable <string> > validationErrorsDictionary =
                new HttpError(modelState, controller.RequestContext.IncludeErrorDetail)
                .ModelState
                .ToDictionary(pair => pair.Key, pair => (IEnumerable <string>)pair.Value);

            var readOnlyValidationErrors =
                new ReadOnlyDictionary <string, IEnumerable <string> >(validationErrorsDictionary);

            var response = new FailResponse(readOnlyValidationErrors);

            _result = new JSendResult <FailResponse>(HttpStatusCode.BadRequest, response, controller);
        }
Esempio n. 10
0
        /// <summary>Creates an <see cref="HttpResponseMessage"/> asynchronously.</summary>
        /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
        /// <returns>A task that, when completed, contains the <see cref="HttpResponseMessage"/>.</returns>
        public Task <HttpResponseMessage> ExecuteAsync(CancellationToken cancellationToken)
        {
            var result = new JSendResult <SuccessResponse>(StatusCode, SuccessResponse, _dependencies.RequestMessage);

            return(result.ExecuteAsync(cancellationToken));
        }
Esempio n. 11
0
 private JSendOkResult(JSendResult <SuccessResponse> .IDependencyProvider dependencies)
 {
     _dependencies = dependencies;
 }
Esempio n. 12
0
        /// <summary>Initializes a new instance of <see cref="JSendExceptionResult"/>.</summary>
        /// <param name="message">A meaningful, end-user-readable (or at the least log-worthy) message, explaining what went wrong.</param>
        /// <param name="errorCode">A numeric code corresponding to the error, if applicable.</param>
        /// <param name="data"> An optional generic container for any other information about the error.</param>
        /// <param name="controller">The controller from which to obtain the dependencies needed for execution.</param>
        public JSendInternalServerErrorResult(string message, int?errorCode, object data, ApiController controller)
        {
            var response = new ErrorResponse(message, errorCode, data);

            _result = new JSendResult <ErrorResponse>(HttpStatusCode.InternalServerError, response, controller);
        }
Esempio n. 13
0
 private JSendOkResult(T content, JSendResult <SuccessResponse> .IDependencyProvider dependencies)
 {
     Response      = new SuccessResponse(content);
     _dependencies = dependencies;
 }
Esempio n. 14
0
        /// <summary>Creates an <see cref="HttpResponseMessage"/> asynchronously.</summary>
        /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
        /// <returns>A task that, when completed, contains the <see cref="HttpResponseMessage"/>.</returns>
        public Task <HttpResponseMessage> ExecuteAsync(CancellationToken cancellationToken)
        {
            var result = new JSendResult <ErrorResponse>(StatusCode, Response, Request);

            return(result.ExecuteAsync(cancellationToken));
        }