Class FromResultToActionResultExtension
Converts a FluentResults.Result or FluentResults.Result<TValue> (or a task of it) into an MVC ActionResult for controller actions.
public static class FromResultToActionResultExtension
- Inheritance
-
FromResultToActionResultExtension
- Inherited Members
Examples
[HttpGet("{id}")]
public Task<ActionResult<OrderDto>> Get(int id)
=> _orders.GetAsync(id).ToActionOkResultAsync(); // _orders.GetAsync returns Task<Result<OrderDto>>
[HttpPost]
public Task<ActionResult<OrderDto>> Create(NewOrder order)
=> _orders.CreateAsync(order).ToActionCreatedResultAsync(new Uri("/orders", UriKind.Relative));
Remarks
The ToActionOkResult family answers 200 OK with the value (or 204 No Content for a non-generic FluentResults.Result);
the ToActionCreatedResult family answers 201 Created with a location. A failed result is turned into an
ObjectResult whose value is the ProblemDetails built by FromResultToProblemDetailExtension.
The overloads on a Task or ValueTask await it first; the ones on a plain result do not await anything. The overloads with a mapper project the value before it is written to the response.
Methods
ToActionCreatedResult(Result, Uri?)
Converts the result to an ActionResult: 201 Created with the given location on success, an ObjectResult carrying the ProblemDetails on failure.
public static ActionResult ToActionCreatedResult(this Result result, Uri? location)
Parameters
resultResultThe result to convert.
locationUriThe URI of the created resource, set in the
Locationheader; may be null.
Returns
- ActionResult
The HTTP response representing the outcome of the result.
Remarks
The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.
ToActionCreatedResultAsync(Result, Uri?)
Converts the result to an ActionResult: 201 Created with the given location on success, an ObjectResult carrying the ProblemDetails on failure.
public static Task<ActionResult> ToActionCreatedResultAsync(this Result result, Uri? location)
Parameters
resultResultThe result to convert.
locationUriThe URI of the created resource, set in the
Locationheader; may be null.
Returns
- Task<ActionResult>
The HTTP response representing the outcome of the result.
Remarks
The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.
ToActionCreatedResultAsync(Task<Result>, Uri?)
Awaits the task, then converts the result to an ActionResult: 201 Created with the given location on success, an ObjectResult carrying the ProblemDetails on failure.
public static Task<ActionResult> ToActionCreatedResultAsync(this Task<Result> result, Uri? location)
Parameters
resultTask<Result>The task producing the result to convert.
locationUriThe URI of the created resource, set in the
Locationheader; may be null.
Returns
- Task<ActionResult>
The HTTP response representing the outcome of the result.
Remarks
The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.
ToActionCreatedResultAsync<TResult>(Result<TResult>, Uri?)
Converts the result to an ActionResult: 201 Created with the given location and the value of the result on success, an ObjectResult carrying the ProblemDetails on failure.
public static Task<ActionResult> ToActionCreatedResultAsync<TResult>(this Result<TResult> result, Uri? location)
Parameters
resultResult<TResult>The result to convert.
locationUriThe URI of the created resource, set in the
Locationheader; may be null.
Returns
- Task<ActionResult>
The HTTP response representing the outcome of the result.
Type Parameters
TResultThe type of the value carried by the result.
Remarks
A null value yields a 201 object result with a null body and no location. The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.
ToActionCreatedResultAsync<TResult>(Task<Result<TResult>>, Uri?)
Awaits the task, then converts the result to an ActionResult: 201 Created with the given location and the value of the result on success, an ObjectResult carrying the ProblemDetails on failure.
public static Task<ActionResult<TResult>> ToActionCreatedResultAsync<TResult>(this Task<Result<TResult>> result, Uri? location)
Parameters
resultTask<Result<TResult>>The task producing the result to convert.
locationUriThe URI of the created resource, set in the
Locationheader; may be null.
Returns
- Task<ActionResult<TResult>>
The HTTP response representing the outcome of the result.
Type Parameters
TResultThe type of the value carried by the result.
Remarks
A null value yields a 201 object result with a null body and no location. The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.
ToActionCreatedResultAsync<TResult>(ValueTask<Result<TResult>>, Uri?)
Awaits the value task, then converts the result to an ActionResult: 201 Created with the given location and the value of the result on success, an ObjectResult carrying the ProblemDetails on failure.
public static ValueTask<ActionResult<TResult>> ToActionCreatedResultAsync<TResult>(this ValueTask<Result<TResult>> result, Uri? location)
Parameters
resultValueTask<Result<TResult>>The value task producing the result to convert.
locationUriThe URI of the created resource, set in the
Locationheader; may be null.
Returns
- ValueTask<ActionResult<TResult>>
The HTTP response representing the outcome of the result.
Type Parameters
TResultThe type of the value carried by the result.
Remarks
A null value yields a 201 object result with a null body and no location. The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.
ToActionCreatedResultAsync<TResult, T>(Result<TResult>, Uri?, Func<TResult, Task<T>>)
Converts the result to an ActionResult: 201 Created with the given location and the value produced by asyncMapper on success, an ObjectResult carrying the ProblemDetails on failure.
public static Task<ActionResult> ToActionCreatedResultAsync<TResult, T>(this Result<TResult> result, Uri? location, Func<TResult, Task<T>> asyncMapper)
Parameters
resultResult<TResult>The result to convert.
locationUriThe URI of the created resource, set in the
Locationheader; may be null.asyncMapperFunc<TResult, Task<T>>Asynchronously maps the value of the result to the value returned to the caller.
Returns
- Task<ActionResult>
The HTTP response representing the outcome of the result.
Type Parameters
TResultThe type of the value carried by the result.
TThe type of the value returned to the caller once mapped.
Remarks
The mapper is not invoked when the successful result carries a null value. A null value yields a 201 object result with a null body and no location. The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.
Exceptions
- ArgumentNullException
asyncMapperis null.
ToActionCreatedResultAsync<TResult, T>(Result<TResult>, Uri?, Func<TResult, T>)
Converts the result to an ActionResult: 201 Created with the given location and the value produced by mapper on success, an ObjectResult carrying the ProblemDetails on failure.
public static Task<ActionResult> ToActionCreatedResultAsync<TResult, T>(this Result<TResult> result, Uri? location, Func<TResult, T> mapper)
Parameters
resultResult<TResult>The result to convert.
locationUriThe URI of the created resource, set in the
Locationheader; may be null.mapperFunc<TResult, T>Maps the value of the result to the value returned to the caller.
Returns
- Task<ActionResult>
The HTTP response representing the outcome of the result.
Type Parameters
TResultThe type of the value carried by the result.
TThe type of the value returned to the caller once mapped.
Remarks
The mapper is not invoked when the successful result carries a null value. A null value yields a 201 object result with a null body and no location. The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.
Exceptions
- ArgumentNullException
mapperis null.
ToActionCreatedResultAsync<TResult, T>(Task<Result<TResult>>, Uri?, Func<TResult, Task<T>>)
Awaits the task, then converts the result to an ActionResult: 201 Created with the given location and the value produced by asyncMapper on success, an ObjectResult carrying the ProblemDetails on failure.
public static Task<ActionResult<T>> ToActionCreatedResultAsync<TResult, T>(this Task<Result<TResult>> result, Uri? location, Func<TResult, Task<T>> asyncMapper)
Parameters
resultTask<Result<TResult>>The task producing the result to convert.
locationUriThe URI of the created resource, set in the
Locationheader; may be null.asyncMapperFunc<TResult, Task<T>>Asynchronously maps the value of the result to the value returned to the caller.
Returns
- Task<ActionResult<T>>
The HTTP response representing the outcome of the result.
Type Parameters
TResultThe type of the value carried by the result.
TThe type of the value returned to the caller once mapped.
Remarks
The mapper is not invoked when the successful result carries a null value. A null value yields a 201 object result with a null body and no location. The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.
Exceptions
- ArgumentNullException
asyncMapperis null.
ToActionCreatedResultAsync<TResult, T>(Task<Result<TResult>>, Uri?, Func<TResult, T>)
Awaits the task, then converts the result to an ActionResult: 201 Created with the given location and the value produced by mapper on success, an ObjectResult carrying the ProblemDetails on failure.
public static Task<ActionResult<T>> ToActionCreatedResultAsync<TResult, T>(this Task<Result<TResult>> result, Uri? location, Func<TResult, T> mapper)
Parameters
resultTask<Result<TResult>>The task producing the result to convert.
locationUriThe URI of the created resource, set in the
Locationheader; may be null.mapperFunc<TResult, T>Maps the value of the result to the value returned to the caller.
Returns
- Task<ActionResult<T>>
The HTTP response representing the outcome of the result.
Type Parameters
TResultThe type of the value carried by the result.
TThe type of the value returned to the caller once mapped.
Remarks
The mapper is not invoked when the successful result carries a null value. A null value yields a 201 object result with a null body and no location. The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.
Exceptions
- ArgumentNullException
mapperis null.
ToActionCreatedResultAsync<TResult, T>(ValueTask<Result<TResult>>, Uri?, Func<TResult, Task<T>>)
Awaits the value task, then converts the result to an ActionResult: 201 Created with the given location and the value produced by asyncMapper on success, an ObjectResult carrying the ProblemDetails on failure.
public static Task<ActionResult<T>> ToActionCreatedResultAsync<TResult, T>(this ValueTask<Result<TResult>> result, Uri? location, Func<TResult, Task<T>> asyncMapper)
Parameters
resultValueTask<Result<TResult>>The value task producing the result to convert.
locationUriThe URI of the created resource, set in the
Locationheader; may be null.asyncMapperFunc<TResult, Task<T>>Asynchronously maps the value of the result to the value returned to the caller.
Returns
- Task<ActionResult<T>>
The HTTP response representing the outcome of the result.
Type Parameters
TResultThe type of the value carried by the result.
TThe type of the value returned to the caller once mapped.
Remarks
The mapper is not invoked when the successful result carries a null value. A null value yields a 201 object result with a null body and no location. The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.
Exceptions
- ArgumentNullException
asyncMapperis null.
ToActionCreatedResultAsync<TResult, T>(ValueTask<Result<TResult>>, Uri?, Func<TResult, T>)
Awaits the value task, then converts the result to an ActionResult: 201 Created with the given location and the value produced by mapper on success, an ObjectResult carrying the ProblemDetails on failure.
public static ValueTask<ActionResult<T>> ToActionCreatedResultAsync<TResult, T>(this ValueTask<Result<TResult>> result, Uri? location, Func<TResult, T> mapper)
Parameters
resultValueTask<Result<TResult>>The value task producing the result to convert.
locationUriThe URI of the created resource, set in the
Locationheader; may be null.mapperFunc<TResult, T>Maps the value of the result to the value returned to the caller.
Returns
- ValueTask<ActionResult<T>>
The HTTP response representing the outcome of the result.
Type Parameters
TResultThe type of the value carried by the result.
TThe type of the value returned to the caller once mapped.
Remarks
The mapper is not invoked when the successful result carries a null value. A null value yields a 201 object result with a null body and no location. The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.
Exceptions
- ArgumentNullException
mapperis null.
ToActionCreatedResult<TResult>(Result<TResult>, Uri?)
Converts the result to an ActionResult: 201 Created with the given location and the value of the result on success, an ObjectResult carrying the ProblemDetails on failure.
public static ActionResult<TResult> ToActionCreatedResult<TResult>(this Result<TResult> result, Uri? location)
Parameters
resultResult<TResult>The result to convert.
locationUriThe URI of the created resource, set in the
Locationheader; may be null.
Returns
- ActionResult<TResult>
The HTTP response representing the outcome of the result.
Type Parameters
TResultThe type of the value carried by the result.
Remarks
A null value yields a 201 object result with a null body and no location. The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.
ToActionCreatedResult<TResult, T>(Result<TResult>, Uri?, Func<TResult, T>)
Converts the result to an ActionResult: 201 Created with the given location and the value produced by mapper on success, an ObjectResult carrying the ProblemDetails on failure.
public static ActionResult<T> ToActionCreatedResult<TResult, T>(this Result<TResult> result, Uri? location, Func<TResult, T> mapper)
Parameters
resultResult<TResult>The result to convert.
locationUriThe URI of the created resource, set in the
Locationheader; may be null.mapperFunc<TResult, T>Maps the value of the result to the value returned to the caller.
Returns
- ActionResult<T>
The HTTP response representing the outcome of the result.
Type Parameters
TResultThe type of the value carried by the result.
TThe type of the value returned to the caller once mapped.
Remarks
The mapper is not invoked when the successful result carries a null value. A null value yields a 201 object result with a null body and no location. The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.
Exceptions
- ArgumentNullException
mapperis null.
ToActionOkResult(Result)
Converts the result to an ActionResult: 204 No Content on success, an ObjectResult carrying the ProblemDetails on failure.
public static ActionResult ToActionOkResult(this Result result)
Parameters
resultResultThe result to convert.
Returns
- ActionResult
The HTTP response representing the outcome of the result.
Remarks
The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.
ToActionOkResultAsync(Result)
Converts the result to an ActionResult: 204 No Content on success, an ObjectResult carrying the ProblemDetails on failure.
public static Task<ActionResult> ToActionOkResultAsync(this Result result)
Parameters
resultResultThe result to convert.
Returns
- Task<ActionResult>
The HTTP response representing the outcome of the result.
Remarks
The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.
ToActionOkResultAsync(Task<Result>)
Awaits the task, then converts the result to an ActionResult: 204 No Content on success, an ObjectResult carrying the ProblemDetails on failure.
public static Task<ActionResult> ToActionOkResultAsync(this Task<Result> result)
Parameters
resultTask<Result>The task producing the result to convert.
Returns
- Task<ActionResult>
The HTTP response representing the outcome of the result.
Remarks
The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.
ToActionOkResultAsync(ValueTask<Result>)
Awaits the value task, then converts the result to an ActionResult: 204 No Content on success, an ObjectResult carrying the ProblemDetails on failure.
public static ValueTask<ActionResult> ToActionOkResultAsync(this ValueTask<Result> result)
Parameters
resultValueTask<Result>The value task producing the result to convert.
Returns
- ValueTask<ActionResult>
The HTTP response representing the outcome of the result.
Remarks
The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.
ToActionOkResultAsync<TResult>(Task<Result<TResult>>)
Awaits the task, then converts the result to an ActionResult: 200 OK containing the value of the result on success, an ObjectResult carrying the ProblemDetails on failure.
public static Task<ActionResult<TResult>> ToActionOkResultAsync<TResult>(this Task<Result<TResult>> result)
Parameters
resultTask<Result<TResult>>The task producing the result to convert.
Returns
- Task<ActionResult<TResult>>
The HTTP response representing the outcome of the result.
Type Parameters
TResultThe type of the value carried by the result.
Remarks
A null value yields a 200 response with a null body. The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.
ToActionOkResultAsync<TResult>(ValueTask<Result<TResult>>)
Awaits the value task, then converts the result to an ActionResult: 200 OK containing the value of the result on success, an ObjectResult carrying the ProblemDetails on failure.
public static ValueTask<ActionResult<TResult>> ToActionOkResultAsync<TResult>(this ValueTask<Result<TResult>> result)
Parameters
resultValueTask<Result<TResult>>The value task producing the result to convert.
Returns
- ValueTask<ActionResult<TResult>>
The HTTP response representing the outcome of the result.
Type Parameters
TResultThe type of the value carried by the result.
Remarks
A null value yields a 200 response with a null body. The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.
ToActionOkResultAsync<TResult, T>(Result<TResult>, Func<TResult, Task<T>>)
Converts the result to an ActionResult: 200 OK containing the value produced by asyncMapper on success, an ObjectResult carrying the ProblemDetails on failure.
public static Task<ActionResult<T>> ToActionOkResultAsync<TResult, T>(this Result<TResult> result, Func<TResult, Task<T>> asyncMapper)
Parameters
resultResult<TResult>The result to convert.
asyncMapperFunc<TResult, Task<T>>Asynchronously maps the value of the result to the value returned to the caller.
Returns
- Task<ActionResult<T>>
The HTTP response representing the outcome of the result.
Type Parameters
TResultThe type of the value carried by the result.
TThe type of the value returned to the caller once mapped.
Remarks
The mapper is not invoked when the successful result carries a null value. A null value yields a 200 response with a null body. The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.
Exceptions
- ArgumentNullException
asyncMapperis null.
ToActionOkResultAsync<TResult, T>(Task<Result<TResult>>, Func<TResult, Task<T>>)
Awaits the task, then converts the result to an ActionResult: 200 OK containing the value produced by asyncMapper on success, an ObjectResult carrying the ProblemDetails on failure.
public static Task<ActionResult<T>> ToActionOkResultAsync<TResult, T>(this Task<Result<TResult>> result, Func<TResult, Task<T>> asyncMapper)
Parameters
resultTask<Result<TResult>>The task producing the result to convert.
asyncMapperFunc<TResult, Task<T>>Asynchronously maps the value of the result to the value returned to the caller.
Returns
- Task<ActionResult<T>>
The HTTP response representing the outcome of the result.
Type Parameters
TResultThe type of the value carried by the result.
TThe type of the value returned to the caller once mapped.
Remarks
The mapper is not invoked when the successful result carries a null value. A null value yields a 200 response with a null body. The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.
Exceptions
- ArgumentNullException
asyncMapperis null.
ToActionOkResultAsync<TResult, T>(Task<Result<TResult>>, Func<TResult, T>)
Awaits the task, then converts the result to an ActionResult: 200 OK containing the value produced by mapper on success, an ObjectResult carrying the ProblemDetails on failure.
public static Task<ActionResult<T>> ToActionOkResultAsync<TResult, T>(this Task<Result<TResult>> result, Func<TResult, T> mapper)
Parameters
resultTask<Result<TResult>>The task producing the result to convert.
mapperFunc<TResult, T>Maps the value of the result to the value returned to the caller.
Returns
- Task<ActionResult<T>>
The HTTP response representing the outcome of the result.
Type Parameters
TResultThe type of the value carried by the result.
TThe type of the value returned to the caller once mapped.
Remarks
The mapper is not invoked when the successful result carries a null value. A null value yields a 200 response with a null body. The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.
Exceptions
- ArgumentNullException
mapperis null.
ToActionOkResultAsync<TResult, T>(ValueTask<Result<TResult>>, Func<TResult, Task<T>>)
Awaits the value task, then converts the result to an ActionResult: 200 OK containing the value produced by asyncMapper on success, an ObjectResult carrying the ProblemDetails on failure.
public static Task<ActionResult<T>> ToActionOkResultAsync<TResult, T>(this ValueTask<Result<TResult>> result, Func<TResult, Task<T>> asyncMapper)
Parameters
resultValueTask<Result<TResult>>The value task producing the result to convert.
asyncMapperFunc<TResult, Task<T>>Asynchronously maps the value of the result to the value returned to the caller.
Returns
- Task<ActionResult<T>>
The HTTP response representing the outcome of the result.
Type Parameters
TResultThe type of the value carried by the result.
TThe type of the value returned to the caller once mapped.
Remarks
The mapper is not invoked when the successful result carries a null value. A null value yields a 200 response with a null body. The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.
Exceptions
- ArgumentNullException
asyncMapperis null.
ToActionOkResultAsync<TResult, T>(ValueTask<Result<TResult>>, Func<TResult, T>)
Awaits the value task, then converts the result to an ActionResult: 200 OK containing the value produced by mapper on success, an ObjectResult carrying the ProblemDetails on failure.
public static ValueTask<ActionResult<T>> ToActionOkResultAsync<TResult, T>(this ValueTask<Result<TResult>> result, Func<TResult, T> mapper)
Parameters
resultValueTask<Result<TResult>>The value task producing the result to convert.
mapperFunc<TResult, T>Maps the value of the result to the value returned to the caller.
Returns
- ValueTask<ActionResult<T>>
The HTTP response representing the outcome of the result.
Type Parameters
TResultThe type of the value carried by the result.
TThe type of the value returned to the caller once mapped.
Remarks
The mapper is not invoked when the successful result carries a null value. A null value yields a 200 response with a null body. The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.
Exceptions
- ArgumentNullException
mapperis null.
ToActionOkResult<TResult>(Result<TResult>)
Converts the result to an ActionResult: 200 OK containing the value of the result on success, an ObjectResult carrying the ProblemDetails on failure.
public static ActionResult<TResult> ToActionOkResult<TResult>(this Result<TResult> result)
Parameters
resultResult<TResult>The result to convert.
Returns
- ActionResult<TResult>
The HTTP response representing the outcome of the result.
Type Parameters
TResultThe type of the value carried by the result.
Remarks
A null value yields a 200 response with a null body. The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.
ToActionOkResult<TResult, T>(Result<TResult>, Func<TResult, T>)
Converts the result to an ActionResult: 200 OK containing the value produced by mapper on success, an ObjectResult carrying the ProblemDetails on failure.
public static ActionResult<T> ToActionOkResult<TResult, T>(this Result<TResult> result, Func<TResult, T> mapper)
Parameters
resultResult<TResult>The result to convert.
mapperFunc<TResult, T>Maps the value of the result to the value returned to the caller.
Returns
- ActionResult<T>
The HTTP response representing the outcome of the result.
Type Parameters
TResultThe type of the value carried by the result.
TThe type of the value returned to the caller once mapped.
Remarks
The mapper is not invoked when the successful result carries a null value. A null value yields a 200 response with a null body. The problem details of a failed result are built by ToProblemDetails, see FromResultToProblemDetailExtension.
Exceptions
- ArgumentNullException
mapperis null.