public void OnActionExecuting(ActionExecutingContext context)
        {
            var validator = CreateValidator();

            var model = context.Request.RouteValues[RouteName];
            var result = validator.Validate(model);

            var store = model as IStoreValidationMessages;
            if (store != null)
            {
                store.ValidationMessages.Clear();
                foreach (var error in result.Errors)
                {
                    store.ValidationMessages.Add(error.PropertyName, error.ErrorMessage);
                }
            }

            if (!result.IsValid)
            {
                var flasher = model as IFlasher;
                if (flasher != null)
                {
                    flasher.ClearFlashes();
                    flasher.Flash("Please ensure all fields have been entered correctly.");
                }

                context.OverrideResult = new DoNothingResult();
            }
        }
 public void OnActionExecuting(ActionExecutingContext context)
 {
     context.OverrideResult = new DoNothingResult();
     Assert.IsNotNull(context.ControllerContext);
     Assert.IsNotNull(context.Request);
     Assert.IsNotNull(context.Request.RouteValues);
 }
 public void OnActionExecuting(ActionExecutingContext context)
 {
     Assert.IsNotNull(context.ControllerContext);
     Assert.IsNotNull(context.Request);
     Assert.IsNotNull(context.Request.RouteValues);
     Assert.IsNotNull(context.ModelBinders);
 }
Exemplo n.º 4
0
 public void OnActionExecuting(ActionExecutingContext context)
 {
     if (!Thread.CurrentPrincipal.IsInRole(RoleName))
     {
         MessageService.ShowInformation(string.Format("This action is only available to users in the {0} group. Try elevating before starting the application.", RoleName));
         context.OverrideResult = new DoNothingResult();
     }
 }
 public void OnActionExecuting(ActionExecutingContext context)
 {
     MessageService.ShowInformation(message);
     context.OverrideResult = new DoNothingResult();
 }
Exemplo n.º 6
0
        /// <summary>
        /// Invokes all pre-request filters, before the controller has been invoked.
        /// </summary>
        /// <param name="controllerContext">The controller context.</param>
        /// <param name="modelBinders">The model binders.</param>
        /// <param name="filters">The filters.</param>
        /// <returns></returns>
        protected virtual ActionResult ExecutePreActionFilters(ControllerContext controllerContext, ModelBinderDictionary modelBinders, IEnumerable<IActionFilter> filters)
        {
            controllerContext.Request.ReportProgress(new PreActionFiltersNavigationEvent());

            var context = new ActionExecutingContext(controllerContext, modelBinders);
            foreach (var filter in filters)
            {
                filter.OnActionExecuting(context);
                if (context.OverrideResult != null)
                {
                    return context.OverrideResult;
                }
            }
            return null;
        }
Exemplo n.º 7
0
 public void OnActionExecuting(ActionExecutingContext context)
 {
     Thread.Sleep(200);
 }