コード例 #1
0
        public static IActionResult CreateResponse <T>(this ControllerBase controller, HttpStatusCode statusCode,
                                                       SwaggerResponse <T> result)
        {
            switch (statusCode)
            {
            case HttpStatusCode.OK:
                return(controller.Ok(result.Result));

            case HttpStatusCode.Created:
                if (result.Result is Ronny createRonny)
                {
                    return(controller.Created(new Uri($"{controller.BasePath()}/ronnies/{createRonny.Id}"), createRonny));
                }
                else
                {
                    return(controller.Created("", result.Result));
                }

            case HttpStatusCode.Accepted:
                if (result.Result is Ronny updateRonny)
                {
                    return(controller.Accepted(new Uri($"{controller.BasePath()}/ronnies/{updateRonny.Id}"), updateRonny));
                }
                else
                {
                    return(controller.Accepted("", result.Result));
                }

            case HttpStatusCode.BadRequest:
                return(controller.BadRequest(result.Error));

            default:
                return(controller.StatusCode((int)statusCode));
            }
        }
コード例 #2
0
        public static ActionResult FromServiceOperationResult(
            this ControllerBase controllerBase, ServiceOperationResult result
            )
        {
            switch (result.StatusCode)
            {
            case HttpStatusCode.OK:
                return(controllerBase.Ok());

            case HttpStatusCode.Accepted:
                return(controllerBase.Accepted());

            case HttpStatusCode.Unauthorized:
                return(controllerBase.Unauthorized());

            case HttpStatusCode.NotFound:
                return(controllerBase.NotFound(result.Errors));

            case HttpStatusCode.Conflict:
                return(controllerBase.Conflict(result.Errors));

            case HttpStatusCode.UnprocessableEntity:
                return(controllerBase.UnprocessableEntity(result.Errors));

            case HttpStatusCode.NotImplemented:
                return(controllerBase.StatusCode((int)result.StatusCode, result.Errors));

            default:
                return(controllerBase.BadRequest(result.Errors));
            }
        }
コード例 #3
0
        public static AcceptedResult AcceptedWithCallback(this ControllerBase controller, Callback callback)
        {
            if (callback == null)
            {
                throw new ArgumentNullException(nameof(callback));
            }

            controller.SetCallbackId(callback.Id);
            return(controller.Accepted());
        }
コード例 #4
0
 public IActionResult Accepted(string locationUrl, IResponse response) =>
 _controller.Accepted(locationUrl, response);