internal void SetValueFromMapToDatabase(IDictionary<string, object> values, IDictionary<string, string> map, MobeelizerFieldAccessor field, bool required, IDictionary<string, string> options, MobeelizerErrorsHolder errors)
        {
            String value = null;
            if (map.ContainsKey(GetFieldName(field.Name)))
            {
                value = map[GetFieldName(field.Name)];
            }
            else if (map.ContainsKey(field.Name))
            {
                value = map[field.Name];
            }

            if (value == null && required)
            {
                errors.AddFieldCanNotBeEmpty(field.Name);
                return;
            }

            if (value == null)
            {
                SetNullValueFromMapToDatabase(values, field, options, errors);
            }
            else
            {
                SetNotNullValueFromMapToDatabase(values, value, field, options, errors);
            }
        }
        private bool ValidateValue(MobeelizerFieldAccessor field, double doubleValue, IDictionary<string, string> options, MobeelizerErrorsHolder errors)
        {
            bool includeMaxValue = GetIncludeMaxValue(options);
            bool includeMinValue = GetIncludeMinValue(options);
            Double minValue = Double.Parse(GetMinValue(options));
            Double maxValue = Double.Parse(GetMaxValue(options));

            if (includeMaxValue && doubleValue > maxValue)
            {
                errors.AddFieldMustBeLessThanOrEqualTo(field.Name, maxValue);
                return false;
            }

            if (!includeMaxValue && doubleValue >= Double.MaxValue)
            {
                errors.AddFieldMustBeLessThan(field.Name, maxValue);
                return false;
            }

            if (includeMinValue && doubleValue < minValue)
            {
                errors.AddFieldMustBeGreaterThanOrEqual(field.Name, minValue);
                return false;
            }

            if (!includeMinValue && doubleValue <= Double.MinValue)
            {
                errors.AddFieldMustBeGreaterThan(field.Name, minValue);
                return false;
            }

            return true;
        }
        private bool ValidateValue(MobeelizerFieldAccessor field, string value, IDictionary<string, string> options, MobeelizerErrorsHolder errors)
        {
            int maxLength = GetMaxLength(options);

            if (((String)value).Length > maxLength)
            {
                errors.AddFieldIsTooLong(field.Name, maxLength);
                return false;
            }

            return true;
        }
        public void Validate(IDictionary<String, object> values, MobeelizerFieldAccessor field, bool required, IDictionary<String, String> options, MobeelizerErrorsHolder errors)
        {
            Object value = values[field.Name];

            if (value == null && required)
            {
                errors.AddFieldCanNotBeEmpty(field.Name);
                return;
            }

            if (value != null)
            {
                ValidateValue(value, field, options, errors);
            }
        }
        protected override void ValidateValue(object value, MobeelizerFieldAccessor field, IDictionary<string, string> options, MobeelizerErrorsHolder errors)
        {
            String stringValue = (String)value;

            if (!errors.IsValid)
            {
                return;
            }

            if (!((MobeelizerDatabase)Mobeelizer.GetDatabase()).Exists(options["model"], stringValue))
            {
                errors.AddFieldMissingReferenceError(field.Name, stringValue);
                return;
            }
        }
        private bool ValidateValue(MobeelizerFieldAccessor field, long longValue, IDictionary<string, string> options, MobeelizerErrorsHolder errors)
        {
            int maxValue = GetMaxValue(options);
            int minValue = GetMinValue(options);

            if (longValue > maxValue)
            {
                errors.AddFieldMustBeLessThan(field.Name, (long)maxValue);
                return false;
            }

            if (longValue < minValue)
            {
                errors.AddFieldMustBeGreaterThan(field.Name, (long)minValue);
                return false;
            }

            return true;
        }
Example #7
0
        internal MobeelizerField(Type type, Definition.MobeelizerModelFieldDefinition radField, Definition.MobeelizerModelFieldCredentialsDefinition fieldCredentials)
        {
            this.field            = radField;
            this.fieldCredentials = fieldCredentials;
            this.Name             = radField.Name;
            this.FieldType        = radField.Type;
            this.accesor          = new MobeelizerFieldAccessor(type, GetPropertyName(this.Name));
            PropertyInfo info = type.GetProperty(this.accesor.Name);

            if (info == null)
            {
                throw new ConfigurationException("Model '" + type.Name + "' does not contains property '" + this.accesor.Name + "'.");
            }

            if (!FieldType.Supports(info.PropertyType))
            {
                throw new ConfigurationException("Problem with model '" + type.Name + "', property '" + this.Name + "' type (" + info.PropertyType.Name + ") not supported.");
            }
        }
 protected override void ValidateValue(object value, MobeelizerFieldAccessor field, IDictionary<string, string> options, MobeelizerErrorsHolder errors)
 {
     ValidateValue(field, (int)value, options, errors);
 }
 protected override void SetNullValueFromMapToDatabase(IDictionary<string, object> values, MobeelizerFieldAccessor field, IDictionary<string, string> options, MobeelizerErrorsHolder errors)
 {
     values.Add(field.Name, null);
 }
 protected override void SetNotNullValueFromMapToDatabase(IDictionary<string, object> values, string value, MobeelizerFieldAccessor field, IDictionary<string, string> options, MobeelizerErrorsHolder errors)
 {
     Int32 intValue = Int32.Parse(value);
     values.Add(field.Name, intValue);
 }
 protected override void SetNotNullValueFromMapToDatabase(IDictionary<string, object> values, string value, MobeelizerFieldAccessor field, IDictionary<string, string> options, MobeelizerErrorsHolder errors)
 {
     DateTime date = new DateTime(TimeSpan.FromMilliseconds(Int64.Parse(value)).Ticks + new DateTime(1970,1,1,2,0,0,DateTimeKind.Utc).Ticks);
     values.Add(field.Name, date);
 }
 protected virtual void ValidateValue(object value, MobeelizerFieldAccessor field, IDictionary<string, string> options, MobeelizerErrorsHolder errors)
 {
 }
 protected virtual void SetNullValueFromMapToDatabase(IDictionary<string, object> values, MobeelizerFieldAccessor field, IDictionary<string, string> options, MobeelizerErrorsHolder errors)
 {
 }