public DateTimeOffsetVm(PropertyVm model) { var dateAttr = model.GetCustomAttributes() .OfType<DataTypeAttribute>() .FirstOrDefault(dt => dt.DataType == DataType.Date || dt.DataType == DataType.DateTime) ?? new DataTypeAttribute(DataType.DateTime); var isDate = dateAttr.DataType == DataType.Date; var displayFormatAttribute = model.GetCustomAttributes().OfType<DisplayFormatAttribute>().SingleOrDefault(); stringFormat = (displayFormatAttribute != null ? displayFormatAttribute.DataFormatString : null) ?? (isDate ? "dd MMM yyyy" : "g"); behaviour = isDate ? "datepicker" : "datetimepicker"; if (model.Value is string) valueAsString = model.Value as string; else { var dateTimeOffset = model.Value as DateTimeOffset?; if (dateTimeOffset == null) { valueAsString = ""; } else { valueAsString = ((DateTimeOffset?) model.Value).Value.ToString(stringFormat); } } }
private static IEnumerable<ModelClientValidationRule> GetRulesFromAttributes(PropertyVm property) { return property.GetCustomAttributes() .SelectMany(attribute => UnobtrusiveValidationAttributeRules, (attribute, rule) => rule(property, attribute)) .Where(r => r != null); }
public static string GetInputTypeFromDataTypeAttribute(PropertyVm Model) { var dataAttributes = Model.GetCustomAttributes().OfType<DataTypeAttribute>().ToList(); var inputType = "text"; if (dataAttributes.Any(da => da.DataType == DataType.Password)) inputType = "password"; if (dataAttributes.Any(da => da.DataType == DataType.MultilineText)) inputType = "textarea"; return inputType; }
public static bool UseRadio(PropertyVm vm) { return vm.GetCustomAttributes().OfType<DataTypeAttribute>().Any(dt => dt.CustomDataType == "Radio"); }
public static IHtmlString Placeholder(PropertyVm pi) { var placeHolderText = pi.GetCustomAttributes().OfType<PlaceholderAttribute>().Select(a => a.Text).FirstOrDefault(); return Attr((!string.IsNullOrWhiteSpace(placeHolderText)), "placeholder", placeHolderText); }