/// <summary> /// Add command result information onto a <see cref="ModelStateDictionary"/> /// </summary> /// <param name="modelStateDictionary"><see cref="ModelStateDictionary"/> to add to</param> /// <param name="commandResult"><see cref="CommandResult"/> to add from</param> /// <param name="exceptionErrorName">Optional parameter for specifying a error name for the any exception, if not specified the error name will be the name of the exception</param> public static void FromCommandResult(this ModelStateDictionary modelStateDictionary, CommandResult commandResult, string exceptionErrorName = null) { if (commandResult.Invalid) { modelStateDictionary.AddToModelErrors(commandResult.ValidationResults); if (commandResult.CommandValidationMessages != null) { modelStateDictionary.AddToModelErrors(commandResult.CommandValidationMessages); } } else { if (exceptionErrorName == null) { exceptionErrorName = commandResult.Exception.GetType().Name; } modelStateDictionary.AddModelError(exceptionErrorName, commandResult.Exception.Message); } }