Exemple #1
0
        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);
        }
Exemple #2
0
        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);
        }
Exemple #3
0
        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;
            }
        }
Exemple #4
0
        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);
            }
        }
Exemple #5
0
        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);
        }
Exemple #6
0
        protected override void SetNotNullValueFromMapToDatabase(IDictionary <string, object> values, string value, MobeelizerFieldAccessor field, IDictionary <string, string> options, MobeelizerErrorsHolder errors)
        {
            Double doubleValue = Double.Parse(value);

            values.Add(field.Name, doubleValue);
        }
Exemple #7
0
 protected override void ValidateValue(object value, MobeelizerFieldAccessor field, IDictionary <string, string> options, MobeelizerErrorsHolder errors)
 {
     ValidateValue(field, (Double)value, options, errors);
 }
Exemple #8
0
 protected override void SetNullValueFromMapToDatabase(IDictionary <string, object> values, MobeelizerFieldAccessor field, IDictionary <string, string> options, MobeelizerErrorsHolder errors)
 {
     values.Add(field.Name, null);
 }
Exemple #9
0
        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);
        }
Exemple #10
0
 internal static void Validate(this MobeelizerFieldType fieldType, IDictionary <String, object> values, MobeelizerFieldAccessor field, bool required, IDictionary <String, String> options, MobeelizerErrorsHolder errors)
 {
     typesMap[fieldType].Validate(values, field, required, options, errors);
 }
Exemple #11
0
 internal static void SetValueFromMapToDatabase(this MobeelizerFieldType fieldType, IDictionary <String, object> values, IDictionary <String, String> map, MobeelizerFieldAccessor field, bool required, IDictionary <String, String> options, MobeelizerErrorsHolder errors)
 {
     typesMap[fieldType].SetValueFromMapToDatabase(values, map, field, required, options, errors);
 }
Exemple #12
0
 protected virtual void ValidateValue(object value, MobeelizerFieldAccessor field, IDictionary <string, string> options, MobeelizerErrorsHolder errors)
 {
 }
Exemple #13
0
 protected virtual void SetNullValueFromMapToDatabase(IDictionary <string, object> values, MobeelizerFieldAccessor field, IDictionary <string, string> options, MobeelizerErrorsHolder errors)
 {
 }
Exemple #14
0
        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);
            }
        }