示例#1
0
 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);
         }
     }
 }
示例#2
0
 private static IEnumerable<ModelClientValidationRule> GetRulesFromAttributes(PropertyVm property)
 {
     return property.GetCustomAttributes()
                    .SelectMany(attribute => UnobtrusiveValidationAttributeRules,
                                (attribute, rule) => rule(property, attribute))
                    .Where(r => r != null);
 }
示例#3
0
 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;
 }
示例#4
0
 public static bool UseRadio(PropertyVm vm)
 {
     return vm.GetCustomAttributes().OfType<DataTypeAttribute>().Any(dt => dt.CustomDataType == "Radio");
 }
示例#5
0
 public static IHtmlString Placeholder(PropertyVm pi)
 {
     var placeHolderText = pi.GetCustomAttributes().OfType<PlaceholderAttribute>().Select(a => a.Text).FirstOrDefault();
     return Attr((!string.IsNullOrWhiteSpace(placeHolderText)), "placeholder", placeHolderText);
 }