Пример #1
0
 public virtual Task <ActionResult> ValueFilter(string property, string value, string selected = null)
 {
     return(Task.Run <ActionResult>(() =>
     {
         IPropertyMetadata p = Metadata.GetProperty(property);
         if (p == null)
         {
             return new HttpStatusCodeResult(404);
         }
         ValueFilterAttribute filterAttribute = p.GetAttribute <ValueFilterAttribute>();
         if (filterAttribute == null)
         {
             return new HttpStatusCodeResult(400);
         }
         IValueFilter filter = (IValueFilter)Resolver.GetService(filterAttribute.ValueFilter);
         ViewBag.Selected = selected;
         ViewBag.IsRequired = p.IsRequired;
         var collection = filter.GetValues(filterAttribute.DependencyProperty, value);
         return View(collection);
     }));
 }
Пример #2
0
        /// <summary>
        /// Get the custom type from property info.
        /// </summary>
        /// <param name="propertyInfo">Property info.</param>
        /// <param name="customType">Custom type if exists.</param>
        /// <param name="isFileUpload">Is property used to upload.</param>
        /// <returns>Custom data type.</returns>
        public static CustomDataType GetCustomDataType(this PropertyInfo propertyInfo, out string customType, out bool isFileUpload)
        {
            CustomDataType type;

            customType   = null;
            isFileUpload = false;
            var customDataType = propertyInfo.GetCustomAttribute <CustomDataTypeAttribute>();

            if (customDataType != null)
            {
                type         = customDataType.Type;
                customType   = customDataType.Custom;
                isFileUpload = customDataType.IsFileUpload;
            }
            else
            {
                Type propertyType           = propertyInfo.PropertyType;
                ValueFilterAttribute filter = propertyInfo.GetCustomAttribute <ValueFilterAttribute>();
                if (propertyType.IsGenericType && propertyType.GetGenericTypeDefinition() == typeof(Nullable <>))
                {
                    propertyType = propertyType.GetGenericArguments()[0];
                }
                if (filter != null)
                {
                    type       = CustomDataType.Other;
                    customType = "ValueFilter";
                }
                else if (propertyType == typeof(DateTime))
                {
                    type = CustomDataType.Date;
                }
                else if (propertyType == typeof(TimeSpan))
                {
                    type = CustomDataType.Time;
                }
                else if (propertyType == typeof(bool))
                {
                    type = CustomDataType.Boolean;
                }
                else if (propertyType == typeof(short) || propertyType == typeof(int) || propertyType == typeof(long))
                {
                    type = CustomDataType.Integer;
                }
                else if (propertyType == typeof(float) || propertyType == typeof(double))
                {
                    type = CustomDataType.Number;
                }
                else if (propertyType == typeof(decimal))
                {
                    type = CustomDataType.Currency;
                }
                else if (propertyType == typeof(byte[]))
                {
                    type         = CustomDataType.File;
                    isFileUpload = true;
                }
                else if (propertyType.IsEnum)
                {
                    type       = CustomDataType.Other;
                    customType = "Enum";
                }
                else if (propertyType.IsGenericType)
                {
                    type       = CustomDataType.Other;
                    customType = "Collection";
                }
                else if (typeof(IEntity).IsAssignableFrom(propertyType))
                {
                    type       = CustomDataType.Other;
                    customType = "Entity";
                }
                else
                {
                    type = CustomDataType.Default;
                }
            }
            return(type);
        }