public ValidationStrategyResult Validate(ValidationStrategyContext context)
        {
            if (context.RawValue != null && context.RawValue.ToString().Length > Length)
            {
                return ValidationStrategyResult.Invalid(new NotificationMessage(ValidationKeys.MAX_LENGTH));
            }

            return ValidationStrategyResult.Valid();
        }
        public ValidationStrategyResult Validate(ValidationStrategyContext context)
        {
            if (context.RawValue == null || context.RawValue.ToString() == string.Empty)
            {
                return ValidationStrategyResult.Invalid(new NotificationMessage(ValidationKeys.REQUIRED));
            }

            return ValidationStrategyResult.Valid();
        }
        public ValidationStrategyResult Validate(ValidationStrategyContext context)
        {
            var rawValue = context.RawValue;
            var enumerable = rawValue as IEnumerable;
            if(enumerable == null || (Length.HasValue && enumerable.Count() != Length.Value))
            {
                return ValidationStrategyResult.Invalid(new NotificationMessage(ValidationKeys.COLLECTION_LENGTH));
            }

            return ValidationStrategyResult.Valid();
        }
        public ValidationStrategyResult Validate(ValidationStrategyContext context)
        {
            var rawValue = context.RawValue;
            if (rawValue != null)
            {
                var value = Convert.ToDecimal(rawValue);
                if (value <= 0)
                {
                    return ValidationStrategyResult.Invalid(new NotificationMessage(ValidationKeys.GREATER_THAN_ZERO));
                }
            }

            return ValidationStrategyResult.Valid();
        }
Beispiel #5
0
        public void Validate(object target, ValidationContext context, Notification notification)
        {
            var declaringType = _typeResolver.ResolveType(target);
            var rawValue = _accessor.GetValue(target);

            var strategyContext = new ValidationStrategyContext(target, rawValue, declaringType, context.Provider, notification);
            var result = _strategy.Validate(strategyContext);
            if(result.IsValid)
            {
                return;
            }

            // TODO -- this is clunky. Need to make the localization pieces easier to consume
            _strategy
                .GetMessageSubstitutions(_accessor)
                .Each((key, value) => result.Message.AddSubstitution(key, value));

            notification
                .RegisterMessage(_accessor, result.Message);
        }
 public bool Equals(ValidationStrategyContext other)
 {
     if (ReferenceEquals(null, other)) return false;
     if (ReferenceEquals(this, other)) return true;
     return Equals(other.Target, Target) && Equals(other.RawValue, RawValue) && Equals(other.DeclaringType, DeclaringType) && Equals(other.Provider, Provider) && Equals(other.Notification, Notification);
 }