/// <summary> /// Called after the command is invoked. /// </summary> protected internal override void OnCommandExecuted(RedwoodRequestContext context, ActionInfo actionInfo, Exception exception) { if (exception != null) { OnException(context, actionInfo, exception); } }
/// <summary> /// Called before the command is executed. /// </summary> protected internal override void OnCommandExecuting(RedwoodRequestContext 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 after the command is executed. /// </summary> protected internal virtual void OnCommandExecuted(RedwoodRequestContext context, ActionInfo actionInfo, Exception exception) { }
/// <summary> /// Called before the command is executed. /// </summary> protected internal virtual void OnCommandExecuting(RedwoodRequestContext context, ActionInfo actionInfo) { }
/// <summary> /// Called when the exception occurs during the command invocation. /// </summary> protected virtual void OnException(RedwoodRequestContext context, ActionInfo actionInfo, Exception ex) { }
/// <summary> /// Resolves the command for the specified post data. /// </summary> public void ResolveCommand(RedwoodRequestContext context, RedwoodView view, string serializedPostData, out ActionInfo actionInfo) { // get properties var data = JObject.Parse(serializedPostData); var path = data["currentPath"].Values<string>().ToArray(); var command = data["command"].Value<string>(); var controlUniqueId = data["controlUniqueId"].Value<string>(); if (string.IsNullOrEmpty(command)) { // empty command actionInfo = null; } else { // find the command target if (!string.IsNullOrEmpty(controlUniqueId)) { var target = view.FindControl(controlUniqueId); if (target == null) { throw new Exception(string.Format("The control with ID '{0}' was not found!", controlUniqueId)); } actionInfo = commandResolver.GetFunction(target, view, context, path, command); } else { actionInfo = commandResolver.GetFunction(view, context, path, command); } } }