Пример #1
0
        public static string GetErrorMessage(IValidatableComponent component, ComponentValidationRule rule)
        {
            if (!string.IsNullOrEmpty(rule.ErrorMessage))
            {
                return(string.Format(rule.ErrorMessage, component.FieldLabel));
            }

            switch (rule.Rule)
            {
            case EnumComponentValidationRule.Mandatory:
                return(string.Format("Please fill the {0} field", component.FieldLabel));

            case EnumComponentValidationRule.Number:
                return(string.Format("Please enter only number in the {0} field", component.FieldLabel));

            case EnumComponentValidationRule.Email:
                return(string.Format("Please enter a valid email for {0} field", component.FieldLabel));

            case EnumComponentValidationRule.Callback:
                return("");

            default:
                return("");
            }
        }
Пример #2
0
        public static IList <ComponentValidationError> ValidateComponent(IValidatableComponent component)
        {
            var errorList = new List <ComponentValidationError>();

            foreach (ComponentValidationRule rule in component.ValidationRules)
            {
                switch (rule.Rule)
                {
                case EnumComponentValidationRule.Mandatory:
                    if (component is dLookupC && ((dLookupC)component).Value == null)
                    {
                        errorList.Add(new ComponentValidationError(component, rule));
                        return(errorList);
                    }

                    if (string.IsNullOrEmpty(component.Text))
                    {
                        errorList.Add(new ComponentValidationError(component, rule));
                        return(errorList);
                    }
                    break;

                case EnumComponentValidationRule.Number:
                    int output;
                    if (!int.TryParse(component.Text, out output))
                    {
                        errorList.Add(new ComponentValidationError(component, rule));
                        return(errorList);
                    }
                    break;
                }
            }

            return(errorList);
        }
Пример #3
0
 public ComponentValidationError(IValidatableComponent component, ComponentValidationRule rule)
 {
     Component = component;
     Rule      = rule;
 }