Ejemplo n.º 1
0
        public static ActionResult BuildNoContentResponse(ControllerBase controller, ApplicationRequestResult requestResult)
        {
            if (!RequestResultIsValid(controller, requestResult, out var actionResult))
            {
                return(actionResult);
            }

            return(controller.NoContent());
        }
Ejemplo n.º 2
0
        public static ActionResult BuildStatusCodeResponse(ControllerBase controller,
                                                           ApplicationRequestResult requestResult,
                                                           int statusCode)
        {
            if (!RequestResultIsValid(controller, requestResult, out var actionResult))
            {
                return(actionResult);
            }

            return(controller.StatusCode(statusCode));
        }
Ejemplo n.º 3
0
        public static ActionResult <T> BuildCreatedAtResponse <T>(ControllerBase controller,
                                                                  ApplicationRequestResult <T> requestResult,
                                                                  string actionName,
                                                                  Func <object> buildRouteValues)
        {
            if (!RequestResultIsValid(controller, requestResult, out var actionResult))
            {
                return(actionResult);
            }

            var routeValues = buildRouteValues();

            return(controller.CreatedAtAction(actionName, routeValues, requestResult.Content));
        }
Ejemplo n.º 4
0
        private static bool RequestResultIsValid(ControllerBase controller,
                                                 ApplicationRequestResult requestResult,
                                                 out ActionResult actionResult)
        {
            if (requestResult.IsBadRequest)
            {
                actionResult = BuildBadRequestResponse(controller, requestResult);
                return(false);
            }

            if (requestResult.IsNotFound)
            {
                actionResult = controller.NotFound();
                return(false);
            }

            actionResult = null;
            return(true);
        }
Ejemplo n.º 5
0
 private static ActionResult <T> BuildBadRequestResponse <T>(ControllerBase controller, ApplicationRequestResult <T> requestResult)
 {
     return(requestResult.ValidationFailures.Any() ?
            controller.BadRequest(requestResult.ValidationFailures) :
            controller.BadRequest());
 }
Ejemplo n.º 6
0
        public static ActionResult <T> BuildRawContentResponse <T>(ControllerBase controller, ApplicationRequestResult <T> requestResult)
        {
            if (!RequestResultIsValid(controller, requestResult, out var actionResult))
            {
                return(actionResult);
            }

            return(requestResult.Content);
        }
Ejemplo n.º 7
0
 protected ApplicationRequestResult <TResponse> NotFound()
 {
     return(ApplicationRequestResult.NotFound <TResponse>());
 }
Ejemplo n.º 8
0
 protected ApplicationRequestResult <TResponse> BadRequest()
 {
     return(ApplicationRequestResult.BadRequest <TResponse>());
 }
Ejemplo n.º 9
0
 protected ApplicationRequestResult <TResponse> Success(TResponse response)
 {
     return(ApplicationRequestResult.Success(response));
 }