Example #1
0
        internal static string GetEditorTemplate(PropertyTypeInfo typeInfo, bool isForeignKey)
        {
            if (isForeignKey)
            {
                return typeInfo.IsCollection ?
                    Templates.Editor.DualList :
                    Templates.Editor.DropDownList;
            }
            if (typeInfo.SourceDataType != null)
            {
                switch (typeInfo.SourceDataType)
                {
                    case SystemDataType.DateTime:
                        return Templates.Editor.DateTime;
                    case SystemDataType.Date:
                        return Templates.Editor.Date;
                    case SystemDataType.Time:
                        return Templates.Editor.Time;
                    case SystemDataType.Url:
                    case SystemDataType.Upload:
                        return Templates.Editor.File;
                    case SystemDataType.ImageUrl:
                        return Templates.Editor.File;
                    case SystemDataType.Currency:
                        return Templates.Editor.Numeric;
                    case SystemDataType.Password:
                        return Templates.Editor.Password;
                    case SystemDataType.Html:
                        return Templates.Editor.Html;
                    case SystemDataType.MultilineText:
                        return Templates.Editor.TextArea;
                    case SystemDataType.PhoneNumber:
                    case SystemDataType.Text:
                    case SystemDataType.EmailAddress:
                    case SystemDataType.CreditCard:
                    case SystemDataType.PostalCode:
                        return Templates.Editor.TextBox;
                }
            }

            switch (typeInfo.DataType)
            {
                case DataType.Enum:
                    return Templates.Editor.DropDownList;
                case DataType.DateTime:
                    return Templates.Editor.DateTime;
                case DataType.Bool:
                    return Templates.Editor.Checkbox;
                case DataType.File:
                    return Templates.Editor.File;
                case DataType.Image:
                    return Templates.Editor.File;
                case DataType.Numeric:
                    return Templates.Editor.Numeric;
                default:
                    return Templates.Editor.TextBox;
            }
        }
        private void SetTemplatesName(object[] attributes, PropertyTypeInfo typeInfo, bool isForeignKey)
        {
            var uiHintAttribute = attributes
                .FirstOrDefault(x =>
                    x.GetType() == typeof(UIHintAttribute)) as UIHintAttribute;
            var templateAttribute = attributes
                .FirstOrDefault(x =>
                    x.GetType() == typeof(TemplateAttribute)) as TemplateAttribute;
            if (uiHintAttribute != null || templateAttribute != null)
            {
                if (uiHintAttribute != null)
                {
                    Editor = Display = uiHintAttribute.UIHint;
                }
                if (templateAttribute != null)
                {
                    if (!templateAttribute.DisplayTemplate.IsNullOrEmpty())
                    {
                        Display = templateAttribute.DisplayTemplate;
                    }
                    if (!templateAttribute.EditorTemplate.IsNullOrEmpty())
                    {
                        Editor = templateAttribute.EditorTemplate;
                    }
                }
            }
            else
            {
                if (isForeignKey)
                {
                    Editor = typeInfo.IsCollection ?
                        Templates.Editor.DualList :
                        Templates.Editor.DropDownList;
                    Display = Templates.Display.Text;
                }
                else if (typeInfo.SourceDataType != null)
                {
                    switch (typeInfo.SourceDataType)
                    {
                        case System.ComponentModel.DataAnnotations.DataType.DateTime:
                            Editor = Templates.Editor.DateTime;
                            Display = Templates.Display.DateTime;
                            break;
                        case System.ComponentModel.DataAnnotations.DataType.Date:
                            Editor = Templates.Editor.Date;
                            Display = Templates.Display.Date;
                            break;
                        case System.ComponentModel.DataAnnotations.DataType.Time:
                            Editor = Templates.Editor.Time;
                            Display = Templates.Display.Time;
                            break;
                        // TODO: for consideration
                        //case DataAnnotations.DataType.Duration:
                        //break;
                        case System.ComponentModel.DataAnnotations.DataType.Url:
                        case System.ComponentModel.DataAnnotations.DataType.Upload:
                            Editor = Templates.Editor.File;
                            Display = Templates.Display.Link;
                            break;
                        case System.ComponentModel.DataAnnotations.DataType.ImageUrl:
                            Editor = Templates.Editor.File;
                            Display = Templates.Display.Image;
                            break;
                        case System.ComponentModel.DataAnnotations.DataType.Currency:
                            Editor = Templates.Editor.Numeric;
                            Display = Templates.Display.Numeric;
                            break;
                        case System.ComponentModel.DataAnnotations.DataType.Password:
                            Editor = Templates.Editor.Password;
                            Display = Templates.Display.Hash;
                            break;
                        case System.ComponentModel.DataAnnotations.DataType.Html:
                            Editor = Templates.Editor.Html;
                            Display = Templates.Display.Html;
                            break;
                        case System.ComponentModel.DataAnnotations.DataType.MultilineText:
                            Editor = Templates.Editor.TextArea;
                            Display = Templates.Display.Text;
                            break;
                        case System.ComponentModel.DataAnnotations.DataType.PhoneNumber:
                        case System.ComponentModel.DataAnnotations.DataType.Text:
                        case System.ComponentModel.DataAnnotations.DataType.EmailAddress:
                        case System.ComponentModel.DataAnnotations.DataType.CreditCard:
                        case System.ComponentModel.DataAnnotations.DataType.PostalCode:
                            Editor = Templates.Editor.TextBox;
                            Display = Templates.Display.Text;
                            break;
                    }
                }

                if (!Display.IsNullOrEmpty()) return;

                switch (typeInfo.DataType)
                {
                    case DataType.Enum:
                        Editor = Templates.Editor.DropDownList;
                        Display = Templates.Display.Text;
                        break;
                    case DataType.DateTime:
                        Editor = Templates.Editor.DateTime;
                        Display = Templates.Display.DateTime;
                        break;
                    case DataType.Bool:
                        Editor = Templates.Editor.CheckBox;
                        Display = Templates.Display.Bool;
                        break;
                    case DataType.File:
                        Editor = Templates.Editor.File;
                        Display = Templates.Display.File;
                        break;
                    case DataType.Image:
                        Editor = Templates.Editor.File;
                        Display = typeInfo.IsFileStoredInDb ?
                            Templates.Display.DbImage :
                            Templates.Display.Image;
                        break;
                    case DataType.Numeric:
                        Editor = Templates.Editor.Numeric;
                        Display = Templates.Display.Numeric;
                        break;
                    default:
                        Editor = Templates.Editor.TextBox;
                        Display = Templates.Display.Text;
                        break;
                }
            }
        }
 public PropertyTemplate(object[] attributes, PropertyTypeInfo typeInfo, bool isForeignKey)
 {
     SetTemplatesName(attributes, typeInfo, isForeignKey);
 }
Example #4
0
        public Property(Entity entity, PropertyInfo property)
        {
            if (property == null)
                throw new ArgumentNullException("property");
            if (entity == null)
                throw new ArgumentNullException("entity");

            Entity = entity;
            PropertyInfo = property;

            Name = property.Name;
            ColumnName = property.Name;
            ControlsAttributes = new Dictionary<string, object>();
            // TODO: determine ColumnName

            TypeInfo = new PropertyTypeInfo(property.PropertyType, Attributes);
            ImageOptions = new ImageOptions(Attributes, Entity.Name);
            Value = new PropertyValue(TypeInfo);
            Template = new PropertyTemplate(Attributes, TypeInfo, IsForeignKey);

            if (TypeInfo.DataType == DataType.Numeric)
            {
                if (TypeInfo.IsFloatingPoint)
                {
                    ControlsAttributes.Add("data-number-number-of-decimals", "4");
                }
                if (TypeInfo.IsNullable)
                {
                    ControlsAttributes.Add("data-number-value", "");
                }
            }

            SetForeignKey(Attributes);

            SetDeleteOption(Attributes);

            IsKey = Attributes.OfType<KeyAttribute>().Any();
            IsLinkKey = Attributes.OfType<LinkKeyAttribute>().Any();

            var columnAttribute =
                Attributes.OfType<ColumnAttribute>().FirstOrDefault();
            if (columnAttribute != null)
            {
                ColumnName = columnAttribute.Name;
            }

            var requiredAttribute =
                Attributes.OfType<RequiredAttribute>().FirstOrDefault();
            if (requiredAttribute != null)
            {
                IsRequired = true;
                RequiredErrorMessage = requiredAttribute.ErrorMessage;
            }

            var displayAttribute =
                Attributes.OfType<DisplayAttribute>().FirstOrDefault();
            if (displayAttribute != null)
            {
                DisplayName = displayAttribute.Name ?? Name.SplitCamelCase();
                Description = displayAttribute.Description;
                GroupName =
                    displayAttribute.GroupName ?? IlaroAdminResources.Others;
            }
            else
            {
                DisplayName = Name.SplitCamelCase();
                GroupName = IlaroAdminResources.Others;
            }
        }
Example #5
0
 public PropertyValue(PropertyTypeInfo typeInfo)
 {
     _typeInfo = typeInfo;
 }
Example #6
0
        public Property(Entity entity, PropertyInfo property)
        {
            if (property == null)
                throw new ArgumentNullException(nameof(property));
            if (entity == null)
                throw new ArgumentNullException(nameof(entity));

            Entity = entity;
            PropertyInfo = property;

            Name = property.Name;
            Column = property.Name;
            ControlsAttributes = new Dictionary<string, object>();

            TypeInfo = new PropertyTypeInfo(property.PropertyType);

            if (TypeInfo.DataType == DataType.Numeric)
            {
                if (TypeInfo.IsFloatingPoint)
                {
                    ControlsAttributes.Add("data-number-number-of-decimals", "4");
                }
                if (TypeInfo.IsNullable)
                {
                    ControlsAttributes.Add("data-number-value", "");
                }
            }

            SetForeignKey();

            Display = Name.SplitCamelCase();
        }
Example #7
0
        internal static string GetDisplayTemplate(PropertyTypeInfo typeInfo, bool isForeignKey)
        {
            if (isForeignKey)
            {
                return Templates.Display.Text;
            }

            if (typeInfo.SourceDataType != null)
            {
                switch (typeInfo.SourceDataType)
                {
                    case SystemDataType.DateTime:
                        return Templates.Display.DateTime;
                    case SystemDataType.Date:
                        return Templates.Display.Date;
                    case SystemDataType.Time:
                        return Templates.Display.DateTime;
                    case SystemDataType.Url:
                    case SystemDataType.Upload:
                        return Templates.Display.Url;
                    case SystemDataType.ImageUrl:
                        return Templates.Display.Image;
                    case SystemDataType.Currency:
                        return Templates.Display.Numeric;
                    case SystemDataType.Password:
                        return Templates.Display.Password;
                    case SystemDataType.Html:
                        return Templates.Display.Html;
                    case SystemDataType.MultilineText:
                        return Templates.Display.Text;
                    case SystemDataType.PhoneNumber:
                    case SystemDataType.Text:
                    case SystemDataType.EmailAddress:
                    case SystemDataType.CreditCard:
                    case SystemDataType.PostalCode:
                        return Templates.Display.Text;
                }
            }

            switch (typeInfo.DataType)
            {
                case DataType.Enum:
                    return Templates.Display.Text;
                case DataType.DateTime:
                    return Templates.Display.DateTime;
                case DataType.Bool:
                    return Templates.Display.Bool;
                case DataType.File:
                    return typeInfo.IsFileStoredInDb ?
                        Templates.Display.DbImage :
                        Templates.Display.File;
                case DataType.Image:
                    return typeInfo.IsFileStoredInDb ?
                        Templates.Display.DbImage :
                        Templates.Display.Image;
                case DataType.Numeric:
                    return Templates.Display.Numeric;
                default:
                    return Templates.Display.Text;
            }
        }
        private void SetTemplatesName(object[] attributes, PropertyTypeInfo typeInfo, bool isForeignKey)
        {
            var uiHintAttribute = attributes
                                  .FirstOrDefault(x =>
                                                  x.GetType() == typeof(UIHintAttribute)) as UIHintAttribute;
            var templateAttribute = attributes
                                    .FirstOrDefault(x =>
                                                    x.GetType() == typeof(TemplateAttribute)) as TemplateAttribute;

            if (uiHintAttribute != null || templateAttribute != null)
            {
                if (uiHintAttribute != null)
                {
                    Editor = Display = uiHintAttribute.UIHint;
                }
                if (templateAttribute != null)
                {
                    if (!templateAttribute.DisplayTemplate.IsNullOrEmpty())
                    {
                        Display = templateAttribute.DisplayTemplate;
                    }
                    if (!templateAttribute.EditorTemplate.IsNullOrEmpty())
                    {
                        Editor = templateAttribute.EditorTemplate;
                    }
                }
            }
            else
            {
                if (isForeignKey)
                {
                    Editor = typeInfo.IsCollection ?
                             Templates.Editor.DualList :
                             Templates.Editor.DropDownList;
                    Display = Templates.Display.Text;
                }
                else if (typeInfo.SourceDataType != null)
                {
                    switch (typeInfo.SourceDataType)
                    {
                    case System.ComponentModel.DataAnnotations.DataType.DateTime:
                        Editor  = Templates.Editor.DateTime;
                        Display = Templates.Display.DateTime;
                        break;

                    case System.ComponentModel.DataAnnotations.DataType.Date:
                        Editor  = Templates.Editor.Date;
                        Display = Templates.Display.Date;
                        break;

                    case System.ComponentModel.DataAnnotations.DataType.Time:
                        Editor  = Templates.Editor.Time;
                        Display = Templates.Display.Time;
                        break;

                    // TODO: for consideration
                    //case DataAnnotations.DataType.Duration:
                    //break;
                    case System.ComponentModel.DataAnnotations.DataType.Url:
                    case System.ComponentModel.DataAnnotations.DataType.Upload:
                        Editor  = Templates.Editor.File;
                        Display = Templates.Display.Link;
                        break;

                    case System.ComponentModel.DataAnnotations.DataType.ImageUrl:
                        Editor  = Templates.Editor.File;
                        Display = Templates.Display.Image;
                        break;

                    case System.ComponentModel.DataAnnotations.DataType.Currency:
                        Editor  = Templates.Editor.Numeric;
                        Display = Templates.Display.Numeric;
                        break;

                    case System.ComponentModel.DataAnnotations.DataType.Password:
                        Editor  = Templates.Editor.Password;
                        Display = Templates.Display.Hash;
                        break;

                    case System.ComponentModel.DataAnnotations.DataType.Html:
                        Editor  = Templates.Editor.Html;
                        Display = Templates.Display.Html;
                        break;

                    case System.ComponentModel.DataAnnotations.DataType.MultilineText:
                        Editor  = Templates.Editor.TextArea;
                        Display = Templates.Display.Text;
                        break;

                    case System.ComponentModel.DataAnnotations.DataType.PhoneNumber:
                    case System.ComponentModel.DataAnnotations.DataType.Text:
                    case System.ComponentModel.DataAnnotations.DataType.EmailAddress:
                    case System.ComponentModel.DataAnnotations.DataType.CreditCard:
                    case System.ComponentModel.DataAnnotations.DataType.PostalCode:
                        Editor  = Templates.Editor.TextBox;
                        Display = Templates.Display.Text;
                        break;
                    }
                }

                if (!Display.IsNullOrEmpty())
                {
                    return;
                }

                switch (typeInfo.DataType)
                {
                case DataType.Enum:
                    Editor  = Templates.Editor.DropDownList;
                    Display = Templates.Display.Text;
                    break;

                case DataType.DateTime:
                    Editor  = Templates.Editor.DateTime;
                    Display = Templates.Display.DateTime;
                    break;

                case DataType.Bool:
                    Editor  = Templates.Editor.CheckBox;
                    Display = Templates.Display.Bool;
                    break;

                case DataType.File:
                    Editor  = Templates.Editor.File;
                    Display = Templates.Display.File;
                    break;

                case DataType.Image:
                    Editor  = Templates.Editor.File;
                    Display = typeInfo.IsFileStoredInDb ?
                              Templates.Display.DbImage :
                              Templates.Display.Image;
                    break;

                case DataType.Numeric:
                    Editor  = Templates.Editor.Numeric;
                    Display = Templates.Display.Numeric;
                    break;

                default:
                    Editor  = Templates.Editor.TextBox;
                    Display = Templates.Display.Text;
                    break;
                }
            }
        }
 public PropertyTemplate(object[] attributes, PropertyTypeInfo typeInfo, bool isForeignKey)
 {
     SetTemplatesName(attributes, typeInfo, isForeignKey);
 }
Example #10
0
 public PropertyValue(PropertyTypeInfo typeInfo)
 {
     _typeInfo = typeInfo;
 }
Example #11
0
        public PropertyValue(object[] attributes, PropertyTypeInfo typeInfo)
        {
            _typeInfo = typeInfo;
            Values = new List<object>();

            var defaultValueAttribute = attributes
                .FirstOrDefault(x =>
                    x.GetType() == typeof(DefaultValueAttribute)) as DefaultValueAttribute;
            if (defaultValueAttribute != null)
                DefaultValue = defaultValueAttribute.Value;
        }
Example #12
0
        public Property(Entity entity, PropertyInfo property)
        {
            if (property == null)
            {
                throw new ArgumentNullException("property");
            }
            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }

            Entity       = entity;
            PropertyInfo = property;

            Name               = property.Name;
            ColumnName         = property.Name;
            ControlsAttributes = new Dictionary <string, object>();
            // TODO: determine ColumnName

            TypeInfo    = new PropertyTypeInfo(property.PropertyType, Attributes);
            FileOptions = new FileOptions(Attributes);
            Value       = new PropertyValue(Attributes, TypeInfo);
            Template    = new PropertyTemplate(Attributes, TypeInfo, IsForeignKey);

            if (TypeInfo.DataType == DataType.Numeric)
            {
                if (TypeInfo.IsFloatingPoint)
                {
                    ControlsAttributes.Add("data-number-number-of-decimals", "4");
                }
                if (TypeInfo.IsNullable)
                {
                    ControlsAttributes.Add("data-number-value", "");
                }
            }

            SetForeignKey(Attributes);

            SetDeleteOption(Attributes);

            IsKey     = Attributes.OfType <KeyAttribute>().Any();
            IsLinkKey = Attributes.OfType <LinkKeyAttribute>().Any();

            var columnAttribute =
                Attributes.OfType <ColumnAttribute>().FirstOrDefault();

            if (columnAttribute != null)
            {
                ColumnName = columnAttribute.Name;
            }

            var requiredAttribute =
                Attributes.OfType <RequiredAttribute>().FirstOrDefault();

            if (requiredAttribute != null)
            {
                IsRequired           = true;
                RequiredErrorMessage = requiredAttribute.ErrorMessage;
            }

            var displayAttribute =
                Attributes.OfType <DisplayAttribute>().FirstOrDefault();

            if (displayAttribute != null)
            {
                DisplayName = displayAttribute.Name ?? Name.SplitCamelCase();
                Description = displayAttribute.Description;
                GroupName   =
                    displayAttribute.GroupName ?? IlaroAdminResources.Others;
            }
            else
            {
                DisplayName = Name.SplitCamelCase();
                GroupName   = IlaroAdminResources.Others;
            }

            SetFormat(Attributes);
        }