/// <summary> /// Wrap the received value in an <see cref="OkObjectResult"/>. /// <para> /// Catches <see cref="ValidationException"/> and converts it to /// an appropriate <see cref="IActionResult"/>. /// </para> /// </summary> /// <typeparam name="TSource">The type of the value.</typeparam> /// <param name="observable">The parent observable.</param> /// <returns>An instance of <see cref="IProviderObservable{IActionResult}"/>.</returns> public static IProviderObservable <IActionResult> ToOkObjectResult <TSource>( this IProviderObservable <TSource> observable) => observable.ToActionResult(s => new OkObjectResult(s));
/// <summary> /// Wrap the received value in an <see cref="CreatedAtRouteResult"/> /// with status code 201 (Created). /// <para> /// Catches <see cref="ValidationException"/> and converts it to /// an appropriate <see cref="IActionResult"/>. /// </para> /// </summary> /// <typeparam name="TSource">The type of the value.</typeparam> /// <param name="observable">The parent observable.</param> /// <param name="routeValuesFactory"> /// The factory function for the route data to use for generating the URL. /// </param> /// <returns>An instance of <see cref="IProviderObservable{IActionResult}"/>.</returns> public static IProviderObservable <IActionResult> ToCreatedAtRouteResult <TSource>( this IProviderObservable <TSource> observable, Func <TSource, object> routeValuesFactory) => observable.ToActionResult(s => new CreatedAtRouteResult(routeValuesFactory(s), s));
/// <summary> /// Emits an <see cref="OptionsResult"/> which lists the allowed /// HTTP verbs. /// <para> /// Catches <see cref="ValidationException"/> and converts it to /// an appropriate <see cref="IActionResult"/>. /// </para> /// </summary> /// <typeparam name="TSource">The type of the value.</typeparam> /// <param name="observable">The parent observable.</param> /// <param name="verbsFactory">A factory function for the allowed HTTP verbs.</param> /// <returns>An instance of <see cref="IProviderObservable{IActionResult}"/>.</returns> public static IProviderObservable <IActionResult> ToOptionsResult <TSource>( this IProviderObservable <TSource> observable, Func <TSource, IEnumerable <HttpVerb> > verbsFactory) => observable.ToActionResult(s => new OptionsResult(verbsFactory(s)));
/// <summary> /// Wrap the received value in an <see cref="ObjectResult"/> /// with status code 202 (Accepted). /// <para> /// Catches <see cref="ValidationException"/> and converts it to /// an appropriate <see cref="IActionResult"/>. /// </para> /// </summary> /// <typeparam name="TSource">The type of the value.</typeparam> /// <param name="observable">The parent observable.</param> /// <returns>An instance of <see cref="IProviderObservable{IActionResult}"/>.</returns> public static IProviderObservable <IActionResult> ToAcceptedObjectResult <TSource>( this IProviderObservable <TSource> observable) => observable.ToActionResult(s => new ObjectResult(s) { StatusCode = StatusCodes.Status202Accepted, });
/// <summary> /// Emits <see cref="NoContentResult"/> on receiving a value. Does not contain the value. /// <para> /// Catches <see cref="ValidationException"/> and converts it to /// an appropriate <see cref="IActionResult"/>. /// </para> /// </summary> /// <typeparam name="TSource">The type of the value.</typeparam> /// <param name="observable">The parent observable.</param> /// <returns>An instance of <see cref="IProviderObservable{IActionResult}"/>.</returns> public static IProviderObservable <IActionResult> ToNoContentResult <TSource>( this IProviderObservable <TSource> observable) => observable.ToActionResult(s => new NoContentResult());