Ejemplo n.º 1
0
        /// <summary>
        /// Determines whether the specified value is valid.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="field">The field.</param>
        /// <param name="summary">The summary.</param>
        /// <returns></returns>
        public override bool IsValid(object value, string field, ref ValidationSummary summary)
        {
            if (value == null)
            {
                return(false);
            }

            if (!(value is String))
            {
                return(false);
            }

            String s      = (String)value;
            bool   result = true;

            if (s.Length < _minLen)
            {
                ValidationEntry ve = new ValidationEntry(false, String.Format(Resources.MinLengthFallenBelow, new object[] { _minLen, field }), field, value);
                summary.Add(ve);
                result = false;
            }

            if (s.Length > _maxLen)
            {
                ValidationEntry ve = new ValidationEntry(false, String.Format(Resources.MaxLengthExceeded, new object[] { _maxLen, field }), field, value);
                summary.Add(ve);
                result = false;
            }

            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Determines whether the specified value is valid.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="field">The field.</param>
        /// <param name="summary">The summary.</param>
        /// <returns></returns>
        public override bool IsValid(object value, string field, ref ValidationSummary summary)
        {
            if (value == null)
            {
                return(false);
            }

            String toValidate;

            if (!(value is String))
            {
                toValidate = value.ToString();
            }
            else
            {
                toValidate = (String)value;
            }

            bool result = true;

            Regex expression = new Regex(_regex, RegexOptions.None);

            if (!expression.IsMatch(toValidate))
            {
                ValidationEntry ve = new ValidationEntry(false, String.Format(_message, new object[] { field }), field, value);
                summary.Add(ve);
                result = false;
            }

            return(result);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Determines whether the specified value is valid.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="field">The field.</param>
        /// <param name="summary">The summary.</param>
        /// <returns></returns>
        public override bool IsValid(object value, string field, ref ValidationSummary summary)
        {
            if (value == null)
            {
                ValidationEntry ve = new ValidationEntry(false, String.Format(_message, new object[] { Alias ?? field }), field, null);
                summary.Add(ve);
                return(false);
            }

            return(true);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Retorna resumo dos erros
        /// </summary>
        /// <param name="validable">Objeto a ser validado</param>
        /// <returns>Resumo dos erros</returns>
        public ValidationSummary GetSummary(Validable validable)
        {
            var summary       = new ValidationSummary();
            var castleSummary = this.runner.GetErrorSummary(validable);

            foreach (var property in castleSummary.InvalidProperties)
            {
                foreach (var error in castleSummary.GetErrorsForProperty(property))
                {
                    summary.Add(property, error);
                }
            }

            return(summary);
        }
        /// <summary>
        /// Determines whether the specified value is valid.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="field">The field.</param>
        /// <param name="summary">The summary.</param>
        public override bool IsValid(object value, string field, ref ValidationSummary summary)
        {
            string   dayText = value as string;
            DateTime day     = DateTime.Now;

            if (DateTime.TryParse(dayText, out day))
            {
                int result = DateTime.Compare(day, DateTime.Now);
                if (result < 0)
                {
                    ValidationEntry ve = new ValidationEntry(false, String.Format(Resources.NoValidDate, new[] { field }), field, value);
                    summary.Add(ve);

                    return(false);
                }
                return(true);
            }

            return(false);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Determines whether the specified value is valid.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="field">The field.</param>
        /// <param name="summary">The summary.</param>
        /// <returns></returns>
        public override bool IsValid(object value, string field, ref ValidationSummary summary)
        {
            if (value == null)
            {
                return(false);
            }

            if (!(value is IComparable))
            {
                return(false);
            }

            IComparable toValidate = (IComparable)value;

            bool   isValid = true;
            string message = string.Empty;

            switch (_restriction)
            {
            case Restriction.Less:
                if (toValidate.CompareTo(_value) >= 0)
                {
                    isValid = false;
                    message = Resources.NumberValidatorLess;
                }
                break;

            case Restriction.LessOrEqual:
                if (toValidate.CompareTo(_value) > 0)
                {
                    isValid = false;
                    message = Resources.NumberValidatorLessEqual;
                }
                break;

            case Restriction.Equal:
                if (toValidate.CompareTo(_value) != 0)
                {
                    isValid = false;
                    message = Resources.NumberValidatorEqual;
                }
                break;

            case Restriction.Greater:
                if (toValidate.CompareTo(_value) <= 0)
                {
                    isValid = false;
                    message = Resources.NumberValidatorGreater;
                }
                break;

            case Restriction.GreaterOrEqual:
                if (toValidate.CompareTo(_value) < 0)
                {
                    isValid = false;
                    message = Resources.NumberValidatorGreaterEqual;
                }
                break;
            }

            if (isValid == false)
            {
                ValidationEntry ve = new ValidationEntry(false, String.Format(message, new[] { field, _value }), field, _value);
                summary.Add(ve);
            }
            return(isValid);
        }