public static ModelStateDictionary AddModelErrors(this ModelStateDictionary modelState, CommandResult result) { foreach (var error in result.Errors) modelState.AddModelError(error.Key, error.Error); return modelState; }
public CommandResult Validate(object instance) { var validationResults = new List<ValidationResult>(); Validator.TryValidateObject(instance, new ValidationContext(instance), validationResults, true); var result = new CommandResult(); foreach (var validationResult in validationResults) result.Add(validationResult.MemberNames.Join(", "), validationResult.ErrorMessage); return result; }