public static ModelMetadataItemBuilder <TModel> RenderAction <TModel>([NotNull] this ModelMetadataItemBuilder <TModel> self, Func <IHtmlHelper, IHtmlContent> action) { self.Template("RenderAction"); self.AddAction( m => { var settings = m.GetAdditionalSettingOrCreateNew <RenderActionSetting>(); settings.Action = action; }); return(self); }
public static ModelMetadataItemBuilder <TModel> RenderViewComponent <TModel>([NotNull] this ModelMetadataItemBuilder <TModel> self, Type componentType, IDictionary <string, object> componentParams) { self.Template("RenderAction"); self.AddAction( m => { var settings = m.GetAdditionalSettingOrCreateNew <RenderActionSetting>(); settings.ViewComponentType = componentType; settings.ViewComponentParams = componentParams; }); return(self); }
/// <summary> /// Sets the range of value, this comes into action when is <code>Required</code> is <code>true</code>. /// </summary> /// <param name="self">The instance.</param> /// <param name="otherProperty">The other property.</param> /// <param name="errorMessage">The error message.</param> /// <param name="errorMessageResourceType">Type of the error message resource.</param> /// <param name="errorMessageResourceName">Name of the error message resource.</param> /// <returns></returns> private static ModelMetadataItemBuilder <TValue> RequiredIfTrue <TValue>(this ModelMetadataItemBuilder <TValue> self, string otherProperty, Func <string> errorMessage, Type errorMessageResourceType, string errorMessageResourceName) { self.AddAction(m => { var validation = m.GetValidationOrCreateNew <RequiredIfTrueAttributeMetadata>(); validation.OtherProperty = otherProperty; validation.ErrorMessage = errorMessage; validation.ErrorMessageResourceType = errorMessageResourceType; validation.ErrorMessageResourceName = errorMessageResourceName; }); return(self); }
/// <summary> /// Sets the range of value, this comes into action when is <code>Required</code> is <code>true</code>. /// </summary> /// <param name="self">The instance.</param> /// <param name="otherProperty">The other property.</param> /// <param name="passOnNull">Pass on null</param> /// <param name="errorMessage">The error message.</param> /// <param name="errorMessageResourceType">Type of the error message resource.</param> /// <param name="errorMessageResourceName">Name of the error message resource.</param> /// <returns></returns> private static ModelMetadataItemBuilder <TValue> LessThan <TValue>(this ModelMetadataItemBuilder <TValue> self, string otherProperty, bool passOnNull, Func <string> errorMessage, Type errorMessageResourceType, string errorMessageResourceName) { self.AddAction(m => { var validation = m.GetValidationOrCreateNew <LessThanAttributeMetadata>(); validation.OtherProperty = otherProperty; validation.PassOnNull = passOnNull; validation.ErrorMessage = errorMessage; validation.ErrorMessageResourceType = errorMessageResourceType; validation.ErrorMessageResourceName = errorMessageResourceName; }); return(self); }
private static ModelMetadataItemBuilder <string> MinimumLength([NotNull] ModelMetadataItemBuilder <string> self, int length, Func <string> errorMessage, Type errorMessageResourceType, string errorMessageResourceName) { self.AddAction( m => { var stringLengthValidation = m.GetValidationOrCreateNew <StringLengthValidationMetadata>(); stringLengthValidation.Minimum = length; stringLengthValidation.ErrorMessage = errorMessage; stringLengthValidation.ErrorMessageResourceType = errorMessageResourceType; stringLengthValidation.ErrorMessageResourceName = errorMessageResourceName; }); return(self); }
private static ModelMetadataItemBuilder <string> Expression([NotNull] ModelMetadataItemBuilder <string> self, string pattern, Func <string> errorMessage, Type errorMessageResourceType, string errorMessageResourceName) { self.AddAction( m => { var regularExpressionValidation = m.GetValidationOrCreateNew <RegularExpressionValidationMetadata>(); regularExpressionValidation.Pattern = pattern; regularExpressionValidation.ErrorMessage = errorMessage; regularExpressionValidation.ErrorMessageResourceType = errorMessageResourceType; regularExpressionValidation.ErrorMessageResourceName = errorMessageResourceName; }); return(self); }
public static ModelMetadataItemBuilder <string> AsUrl([NotNull] this ModelMetadataItemBuilder <string> self) { self.Template("Url"); self.AddAction( m => { if (m.GetValidation <RegularExpressionValidationMetadata>() != null) { throw new InvalidOperationException(ExceptionMessages.CannotApplyUrlWhenThereIsAnActiveExpression); } }); return(Expression(self, UrlExpression, ((UrlErrorMessageResourceType == null) && string.IsNullOrEmpty(UrlErrorMessageResourceName)) ? () => UrlErrorMessage : (Func <string>)null, UrlErrorMessageResourceType, UrlErrorMessageResourceName)); }
private static ModelMetadataItemBuilder <TValue?> Range <TValue>([NotNull] this ModelMetadataItemBuilder <TValue?> self, TValue minimum, TValue maximum, Func <string> errorMessage, Type errorMessageResourceType, string errorMessageResourceName) where TValue : struct, IComparable { self.AddAction( m => { var rangeValidation = m.GetValidationOrCreateNew <RangeValidationMetadata <TValue> >(); rangeValidation.Minimum = minimum; rangeValidation.Maximum = maximum; rangeValidation.ErrorMessage = errorMessage; rangeValidation.ErrorMessageResourceType = errorMessageResourceType; rangeValidation.ErrorMessageResourceName = errorMessageResourceName; }); return(self); }
/// <summary> /// Sets the range of value, this comes into action when is <code>Required</code> is <code>true</code>. /// </summary> /// <param name="self">The instance.</param> /// <param name="otherProperty">The other property.</param> /// <param name="expression"></param> /// <param name="operator"></param> /// <param name="dependentValue"></param> /// <param name="errorMessage">The error message.</param> /// <param name="errorMessageResourceType">Type of the error message resource.</param> /// <param name="errorMessageResourceName">Name of the error message resource.</param> /// <returns></returns> private static ModelMetadataItemBuilder <TValue> RegularExpressionIf <TValue>(this ModelMetadataItemBuilder <TValue> self, string otherProperty, string expression, Operator @operator, object dependentValue, Func <string> errorMessage, Type errorMessageResourceType, string errorMessageResourceName) { self.AddAction(m => { var validation = m.GetValidationOrCreateNew <RegularExpressionIfAttributeMetadata>(); validation.Expression = expression; validation.OtherProperty = otherProperty; validation.Operator = @operator; validation.DependentValue = dependentValue; validation.ErrorMessage = errorMessage; validation.ErrorMessageResourceType = errorMessageResourceType; validation.ErrorMessageResourceName = errorMessageResourceName; }); return(self); }
private static ModelMetadataItemBuilder <TValue> HtmlSelect <TValue>([NotNull] ModelMetadataItemBuilder <TValue> self, string templateName, string viewDataKey, Func <string> optionLabel) { self.AddAction( m => { var selectableElementSetting = m.GetAdditionalSettingOrCreateNew <ModelMetadataItemSelectableElementSetting>(); selectableElementSetting.ViewDataKey = viewDataKey; if (optionLabel != null) { selectableElementSetting.OptionLabel = optionLabel; } m.TemplateName = templateName; }); return(self); }