/// <summary> /// Creates a <see cref="GatewayTimeoutResult"/> object that produces a Gateway Timeout (504) response. /// </summary> /// <param name="controller">MVC controller instance.</param> /// <returns>The created <see cref="GatewayTimeoutResult"/> for the response.</returns> public static GatewayTimeoutResult GatewayTimeout(this ControllerBase controller) => new GatewayTimeoutResult();
/// <summary> /// Creates a <see cref="ServiceUnavailableResult"/> object that produces an empty Service Unavailable (503) response. /// </summary> /// <param name="controller">MVC controller instance.</param> /// <returns>The created <see cref="ServiceUnavailableResult"/> for the response.</returns> public static ServiceUnavailableResult ServiceUnavailable(this ControllerBase controller) => new ServiceUnavailableResult();
/// <summary> /// Creates a <see cref="ServiceUnavailableResult"/> object that produces a Service Unavailable (503) response. /// </summary> /// <param name="controller">MVC controller instance.</param> /// <param name="lengthOfDelay">Length of delay after which the server will be running again.</param> /// <returns>The created <see cref="ServiceUnavailableResult"/> for the response.</returns> public static ServiceUnavailableResult ServiceUnavailable(this ControllerBase controller, string lengthOfDelay) => new ServiceUnavailableResult(lengthOfDelay);
/// <summary> /// Creates an <see cref="NotImplementedResult"/> object that produces a Not Implemented (501) response. /// </summary> /// <param name="controller">MVC controller instance.</param> /// <returns>The created <see cref="NotImplementedResult"/> for the response.</returns> public static NotImplementedResult NotImplemented(this ControllerBase controller) => new NotImplementedResult();
/// <summary> /// Creates a <see cref="BadGatewayResult"/> object that produces a Bad Getaway (502) response. /// </summary> /// <param name="controller">MVC controller instance.</param> /// <returns>The created <see cref="BadGatewayResult"/> for the response.</returns> public static BadGatewayResult BadGateway(this ControllerBase controller) => new BadGatewayResult();
public static string GetStringCookie(this ControllerBase controllerBase, string key) { //read cookie from Request object return(controllerBase.Request.GetStringCookie(key)); }
/// <summary> /// Creates an <see cref="InternalServerErrorResult"/> object that produces an Internal Server Error (500) response. /// </summary> /// <param name="controller">MVC controller instance.</param> /// <returns>The created <see cref="InternalServerErrorResult"/> for the response.</returns> public static InternalServerErrorResult InternalServerError(this ControllerBase controller) => new InternalServerErrorResult();
public static int GetUserId(this ControllerBase controller) { return(controller.User.GetUserId()); }
/// <summary> /// Returns a HTTP 200 OK with a paging result set from an IQueryable. /// </summary> /// <param name="controller">Base controller.</param> /// <param name="source">IQueryable source.</param> /// <returns></returns> public static PagingResult Paging(this ControllerBase controller, IQueryable source) { return(new PagingResult(source)); }
public static void SetJsonCookie <T>(this ControllerBase controllerBase, string key, T value, int?expireTime) { controllerBase.Response.SetJsonCookie <T>(key, value, expireTime); }
public static T GetJsonCookie <T>(this ControllerBase controllerBase, string key) where T : class { //read cookie from Request object return(controllerBase.Request.GetJsonCookie <T>(key)); }
public static ActionResult ValidateAndBadRequest(this ControllerBase controller, object model = null, bool mapModel = false) { controller.UpdateValidations(model, mapModel); return(controller.BadRequest(controller.ModelState)); }
/// <summary> /// Send <paramref name="request"/> through <see cref="IMediator"/>. /// </summary> /// <typeparam name="TResponse">Response type.</typeparam> /// <param name="controller">Controller.</param> /// <param name="request">Request.</param> /// <returns>Response from request.</returns> public static Task <TResponse> SendRequest <TResponse>( this ControllerBase controller, IRequest <TResponse> request) => controller.Mediator().Send(request);
/// <summary> /// Access to <see cref="IMediator"/>. /// </summary> /// <param name="controller">Controller.</param> /// <returns>Mediator.</returns> public static IMediator Mediator(this ControllerBase controller) => (IMediator)controller.HttpContext.RequestServices.GetService(typeof(IMediator));
/// <summary> /// Creates a <see cref="HTTPVersionNotSupportedResult"/> object that produces a HTTP Version Not Supported (505) response. /// </summary> /// <param name="controller">MVC controller instance.</param> /// <param name="value">The precondition failed value to format in the entity body.</param> /// <returns>The created <see cref="HTTPVersionNotSupportedResult"/> for the response.</returns> public static HTTPVersionNotSupportedResult HTTPVersionNotSupported(this ControllerBase controller, object value) => new HTTPVersionNotSupportedResult(value);
/// <summary> /// Returns a HTTP 200 OK with a paging result set from an IQueryable. /// </summary> /// <typeparam name="T">Collection type of source.</typeparam> /// <param name="controller">Base controller.</param> /// <param name="source">IQueryable source.</param> /// <returns></returns> public static PagingResult <T> Paging <T>(this ControllerBase controller, IQueryable <T> source) { return(new PagingResult <T>(source)); }
/// <summary>Create a HTTP action result from a service result.</summary> /// <typeparam name="T">The type of the result data.</typeparam> public static IActionResult ToActionResult <T>(this Result <T> result, Controller controller) => #if NETCOREAPP3_0_OR_GREATER result?.Status switch {
public static void SetStringCookie(this ControllerBase controllerBase, string key, string value, int?expireTime) { controllerBase.Response.SetStringCookie(key, value, expireTime); }