Ejemplo n.º 1
0
 public HandleActionRequest(Controller targetController, Func <Task <IActionResult> > controllerActionHandler, Func <IErrorsViewModel, Task <IActionResult> > onErrorUseThisResultProvider, IErrorsViewModel storeErrorsOn, Action <Exception> onCustomErrorHandling)
 {
     TargetController             = targetController ?? throw new ArgumentNullException(nameof(targetController));
     ControllerActionHandler      = controllerActionHandler ?? throw new ArgumentNullException(nameof(controllerActionHandler));
     OnErrorUseThisResultProvider = onErrorUseThisResultProvider;
     StoreErrorsOn         = storeErrorsOn;
     OnCustomErrorHandling = onCustomErrorHandling;
 }
Ejemplo n.º 2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="targetController"></param>
 /// <param name="controllerActionHandler"></param>
 /// <param name="onErrorUseThisResultProvider">Action to provide result on invalid model. If not specified returns the model with errors</param>
 /// <param name="storeErrorsOn">viewmodel to use in the redirection in case of errors</param>
 /// <param name="onCustomErrorHandling">do not specify if you dont need to handle specific errors. It is called once per domain exception</param>
 /// <returns></returns>
 public static async Task <IActionResult> HandleActionAsync(this Controller targetController,
                                                            Func <Task <IActionResult> > controllerActionHandler,
                                                            Func <IErrorsViewModel, Task <IActionResult> > onErrorUseThisResultProvider,
                                                            IErrorsViewModel storeErrorsOn           = null,
                                                            Action <Exception> onCustomErrorHandling = null)
 {
     if (controllerActionHandler == null)
     {
         throw new ArgumentNullException(nameof(controllerActionHandler));
     }
     return(await HandleActionAsync(new HandleActionRequest(targetController, controllerActionHandler, onErrorUseThisResultProvider, storeErrorsOn, onCustomErrorHandling)));
 }
Ejemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="targetController"></param>
        /// <param name="controllerActionHandler"></param>
        /// <param name="onErrorRedirectToActionName">Action to redirect on invalid model. If not specified returns the model with errors</param>
        /// <param name="storeErrorsOn">viewmodel to use in the redirection in case of errors</param>
        /// <param name="onCustomErrorHandling">do not specify if you dont need to handle specific errors. It is called once per domain exception</param>
        /// <returns></returns>
        public static async Task <IActionResult> HandleActionAsync(this Controller targetController,
                                                                   Func <Task <IActionResult> > controllerActionHandler,
                                                                   string onErrorRedirectToActionName       = null,
                                                                   IErrorsViewModel storeErrorsOn           = null,
                                                                   Action <Exception> onCustomErrorHandling = null)
        {
            var errorRedirectToActionName = onErrorRedirectToActionName != null
                                ? async m => (IActionResult)targetController.RedirectToAction(onErrorRedirectToActionName,
                                                                                              await m.ToValidRouteValueAsync(targetController.HttpContext))
                                : (Func <IErrorsViewModel, Task <IActionResult> >)null;

            return(await targetController.HandleActionAsync(controllerActionHandler, errorRedirectToActionName,
                                                            storeErrorsOn,
                                                            onCustomErrorHandling));
        }