Beispiel #1
0
        public Dictionary <string, string[]> Validate(Context db, Draft draft, ValidationLevel level = ValidationLevel.Warning)
        {
            ValidationLevel[] levels;
            switch (level)
            {
            case ValidationLevel.Error:
                levels = new ValidationLevel[] { ValidationLevel.Error };
                break;

            case ValidationLevel.Warning:
            default:
                levels = new ValidationLevel[] { ValidationLevel.Warning, ValidationLevel.Error };
                break;
            }

            var ValidationErrors = new Dictionary <string, string[]>();

            foreach (var validation in this.Validations)
            {
                if (!levels.Contains(validation.Level))
                {
                    continue;
                }

                var field = db.FormCoreFields.Find(validation.FieldId);
                var key   = field.StoredColumn;

                var errors = new List <string>();
                if (validation.IsNotValid(draft, db))
                {
                    errors.Add(validation.ReadableMessage(field));
                }
                if (errors.Count > 0)
                {
                    ValidationErrors.Add(key, errors.ToArray());
                }
            }
            return(ValidationErrors);
        }
Beispiel #2
0
        public bool IsNotValid(Draft draft, Context db)
        {
            var field = db.FormCoreFields.Find(FieldId);

            if (Type == ValidationType.Presence)
            {
                var val = draft.Data[field.StoredColumn];
                if (val == null)
                {
                    return(true);
                }
                if (val.Type == JTokenType.Array)
                {
                    return(val.Count < field.Columns.Length);
                }
                if (val.Type == JTokenType.String)
                {
                    return(string.IsNullOrEmpty(val.Value as string));
                }
                return(false);
            }

            return(true);
        }
Beispiel #3
0
 public ODraft(Draft instance)
 {
     Id     = instance.Id;
     FormId = instance.Id;
     Data   = instance.Data;
 }