/// <inheritdoc /> protected internal override Task OnCommandExecutingAsync(IDotvvmRequestContext context, ActionInfo actionInfo) { if (!string.IsNullOrEmpty(context.ModelState.ValidationTargetPath)) { var validator = context.Configuration.ServiceLocator.GetService <IViewModelValidator>(); context.ModelState.Errors.AddRange(validator.ValidateViewModel(context.ModelState.ValidationTarget)); context.FailOnInvalidModelState(); } return(Task.FromResult(0)); }
protected internal override Task OnCommandExecutingAsync(IDotvvmRequestContext context, ActionInfo actionInfo) { if (!string.IsNullOrEmpty(context.ModelState.ValidationTargetPath)) { var validator = context.Services.GetRequiredService <IViewModelValidator>(); context.ModelState.Errors.AddRange(validator.ValidateViewModel(context.ModelState.ValidationTarget)); context.FailOnInvalidModelState(); } return(TaskUtils.GetCompletedTask()); }
/// <summary> /// Called before the command is executed. /// </summary> protected internal override void OnCommandExecuting(IDotvvmRequestContext context, ActionInfo actionInfo) { if (!string.IsNullOrEmpty(context.ModelState.ValidationTargetPath)) { // perform the validation context.ModelState.Errors.AddRange(viewModelValidator.ValidateViewModel(context.ModelState.ValidationTarget)); // return the model state when error occurs context.FailOnInvalidModelState(); } base.OnCommandExecuting(context, actionInfo); }
/// <summary> /// Called before the command is executed. /// </summary> protected internal override void OnCommandExecuting(IDotvvmRequestContext context, ActionInfo actionInfo) { if (!string.IsNullOrEmpty(context.ModelState.ValidationTargetPath)) { var viewModelValidator = context.Configuration.ServiceLocator.GetService<IViewModelValidator>(); // perform the validation context.ModelState.Errors.AddRange(viewModelValidator.ValidateViewModel(context.ModelState.ValidationTarget)); // return the model state when error occurs context.FailOnInvalidModelState(); } base.OnCommandExecuting(context, actionInfo); }
private static void HandleValidation(IDotvvmRequestContext context, SwaggerException ex) { var invalidProperties = ParseResponse(ex); foreach (var property in invalidProperties) { foreach (var error in property.Value) { context.ModelState.Errors.Add(new ViewModelValidationError() { PropertyPath = ConvertPropertyName(property.Key), ErrorMessage = error }); } } context.FailOnInvalidModelState(); }