Example #1
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 #2
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;
            }
        }