/// <summary> /// Returns an ErrorInfo for a class level validation result /// </summary> /// <param name="result"> /// The validation result. /// </param> /// <returns> /// The ErrorInfo /// </returns> private static ErrorInfo GetClassLevelErrorInfo(IValidationResult result) { var errorInfo = new ErrorInfo(string.Empty, result.Message); if (typeof(ICaptcha).IsAssignableFrom(result.ClassContext)) { errorInfo = new ErrorInfo("Captcha", result.Message); } else { // Get the validation attributes on the entity type var validatorProperties = result.ClassContext.GetCustomAttributes(false).Where( x => typeof(IValidateMultipleProperties).IsAssignableFrom(x.GetType())); // If the validation message matches one of the attributes messages, // then set the correct property path, based on the primary property name validatorProperties.ForEach( x => { if (result.Message == ((IValidateMultipleProperties)x).Message) { errorInfo = new ErrorInfo( ((ValidationResult)result).InvalidValue.PropertyPath + ((IValidateMultipleProperties)x).PrimaryPropertyName, result.Message); } }); } return errorInfo; }
public void RemoveErrorInfo(ErrorInfo errorInfo) { _errorInfos.Remove(errorInfo); }
public void AddErrorInfo(ErrorInfo errorInfo) { _errorInfos.Add(errorInfo); }