Ejemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BoolMessageItem&lt;T&gt;"/> class.
 /// </summary>
 /// <param name="item">The item.</param>
 /// <param name="success">if set to <c>true</c> [success].</param>
 /// <param name="message">The message.</param>
 /// <param name="errors">List of validation errors messages.</param>
 public BoolResult(T item, bool success, string message, IValidationResults errors)
     : base(item, success, message)
 {
     _errors = errors;
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ValidationException"/> class.
 /// </summary>
 /// <param name="results">The results.</param>
 public ValidationException(IValidationResults results)
 {
     _results = results;
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Create the model action context using existing errors or message collection.
 /// If empty, a default instance will be created.
 /// </summary>
 /// <param name="item"></param>
 /// <param name="errors">Error collection</param>
 public ActionContext(T item, IValidationResults errors) : base(item, errors)
 {
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Create the model action context using existing errors or message collection.
 /// If empty, a default instance will be created.
 /// </summary>
 /// <param name="errors">Error collection</param>
 public ActionContext(IValidationResults errors) : base(errors)
 {
 }
 /// <summary>
 /// Determines if the phone number supplied is a valid US phone number.
 /// </summary>
 /// <param name="phone"></param>
 /// <returns></returns>
 public static bool IsPhoneUS(int phone, IValidationResults errors, string tag)
 {
     return(CheckErrorRegEx(phone.ToString(), false, RegexPatterns.PhoneUS, errors, tag, "Text supplied is not a valid US phone number.", null));
 }
Ejemplo n.º 6
0
        /// <summary>
        /// </summary>
        /// <param name="enumType"></param>
        /// <param name="val"></param>
        /// <param name="results"></param>
        /// <returns></returns>
        public static object GetValue(this EnumLookup lookup, Type enumType, string val, IValidationResults results, string defaultValue)
        {
            // Invalid enum value.
            if (!EnumLookup.IsValid(enumType, val))
            {
                results.Add("Invalid value '" + val + "' for " + enumType.Name);
                return false;
            }

            return EnumLookup.GetValue(enumType, val, defaultValue);
        }
Ejemplo n.º 7
0
 public virtual void Clear()
 {
     _lastValidationResults = new ValidationResults();
 }
        /// <summary>
        /// Determines if the date supplied is a date within the specified bounds.
        /// </summary>
        /// <param name="date"></param>
        /// <param name="checkMinBound"></param>
        /// <param name="checkMaxBound"></param>
        /// <param name="minDate"></param>
        /// <param name="maxDate"></param>
        /// <returns></returns>
        public static bool IsDateWithinRange(DateTime date, bool checkMinBound, bool checkMaxBound, DateTime minDate, DateTime maxDate, IValidationResults errors, string tag)
        {
            if (checkMinBound && date.Date < minDate.Date)
            {
                errors.Add(tag, "Date supplied is less than minimum date " + minDate.ToShortDateString(), null);
                return(false);
            }
            if (checkMaxBound && date.Date > maxDate.Date)
            {
                errors.Add(tag, "Date supplied is more than maximum date " + maxDate.ToShortDateString(), null);
                return(false);
            }

            return(true);
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Validate using the object provided.
 /// </summary>
 /// <param name="target"></param>
 /// <returns></returns>
 public virtual IValidationResults ValidateTarget(object target)
 {
     _lastValidationResults = new ValidationResults() as IValidationResults;
     Validate(new ValidationEvent(target, _lastValidationResults));
     return _lastValidationResults;
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Add a new result to the list of errors.
 /// </summary>
 /// <param name="results"></param>
 /// <param name="key"></param>
 /// <param name="message"></param>
 /// <param name="target"></param>
 protected void AddResult(IValidationResults results, string key, string message)
 {
     results.Add(key, message);
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Validate using the object provided, and add errors to the results list provided.
 /// </summary>
 /// <param name="target"></param>
 /// <param name="results"></param>
 public bool Validate(object target, IValidationResults results)
 {
     return Validate(new ValidationEvent(target, results));
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Validate using the results collection provided.
 /// </summary>
 /// <param name="results"></param>
 /// <returns></returns>
 public virtual IValidationResults Validate(IValidationResults results)
 {
     Validate(new ValidationEvent(Target, results));
     return results;
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Validate data using data provided during initialization/construction.
 /// </summary>
 /// <returns></returns>
 public virtual IValidationResults Validate()
 {
     _lastValidationResults = new ValidationResults() as IValidationResults;
     Validate(Target, _lastValidationResults);
     return _lastValidationResults;
 }
        /// <summary>
        /// Determines if text supplied is numeric and within the min/max bounds.
        /// </summary>
        /// <param name="text">Text to check if it's numeric and within bounds.</param>
        /// <param name="checkMinBound">Whether or not to check</param>
        /// <param name="checkMaxBound"></param>
        /// <param name="min"></param>
        /// <param name="max"></param>
        /// <returns></returns>
        public static bool IsNumericWithinRange(double num, bool checkMinBound, bool checkMaxBound, double min, double max, IValidationResults errors, string tag)
        {
            if (checkMinBound && num < min)
            {
                errors.Add(tag, "Number supplied is less than " + min + ".", null);
                return(false);
            }

            if (checkMaxBound && num > max)
            {
                errors.Add(tag, "Number supplied is more than " + max + ".", null);
                return(false);
            }

            return(true);
        }
Ejemplo n.º 15
0
 public virtual void Clear()
 {
     this._lastValidationResults = new ValidationResults();
 }
        /// <summary>
        /// Determines if the date supplied is a date.
        /// </summary>
        /// <param name="text"></param>
        /// <param name="checkBounds"></param>
        /// <param name="minDate"></param>
        /// <param name="maxDate"></param>
        /// <returns></returns>
        public static bool IsDate(string text, IValidationResults errors, string tag)
        {
            DateTime result = DateTime.MinValue;

            return(CheckError(DateTime.TryParse(text, out result), errors, tag, "Text supplied is not a valid date", null));
        }
Ejemplo n.º 17
0
 public virtual IValidationResults Validate()
 {
     this._lastValidationResults = new ValidationResults();
     this.Validate(this.Target, this._lastValidationResults);
     return(this._lastValidationResults);
 }
 /// <summary>
 /// Determines if the time string specified is a time of day. e.g. 9am
 /// and within the bounds specified.
 /// </summary>
 /// <param name="time"></param>
 /// <param name="checkBounds"></param>
 /// <param name="min"></param>
 /// <param name="max"></param>
 /// <returns></returns>
 public static bool IsTimeOfDayWithinRange(TimeSpan time, bool checkMinBound, bool checkMaxBound, TimeSpan min, TimeSpan max, IValidationResults errors, string tag)
 {
     return(true);
 }
Ejemplo n.º 19
0
 public virtual IValidationResults ValidateTarget(object target)
 {
     this._lastValidationResults = new ValidationResults();
     this.Validate(new ValidationEvent(target, this._lastValidationResults));
     return(this._lastValidationResults);
 }
Ejemplo n.º 20
0
 /// <summary>
 /// Validates the rule and returns a boolMessage.
 /// </summary>
 /// <param name="rule"></param>
 /// <returns></returns>
 public static bool ValidateAndCollect(IValidator validator, IValidationResults results)
 {
     IValidationResults validationResults = validator.Validate(results);
     return validationResults.IsValid;
 }
Ejemplo n.º 21
0
 protected void AddResult(IValidationResults results, string key, string message)
 {
     results.Add(key, message);
 }
Ejemplo n.º 22
0
 public ValidatorFluent(Type typeToCheck, IValidationResults errors)
     : this(typeToCheck, false, errors)
 {
 }
Ejemplo n.º 23
0
 /// <summary>
 /// Validate using the object provided, and add errors to the results list provided.
 /// </summary>
 /// <param name="target"></param>
 /// <param name="results"></param>
 public bool Validate(object target, IValidationResults results)
 {
     return(Validate(new ValidationEvent(target, results)));
 }
Ejemplo n.º 24
0
 /// <summary>
 /// Create the model action context using existing errors or message collection.
 /// If empty, a default instance will be created.
 /// </summary>
 /// <param name="errors">Error collection</param>
 /// <param name="id"></param>
 public ActionContext(IValidationResults errors, int id) : base(errors, id)
 {
 }
Ejemplo n.º 25
0
 /// <summary>
 /// Add a new result to the list of errors.
 /// </summary>
 /// <param name="results"></param>
 /// <param name="key"></param>
 /// <param name="message"></param>
 /// <param name="target"></param>
 protected void AddResult(IValidationResults results, string key, string message, object target)
 {
     results.Add(key, message, target);
 }
Ejemplo n.º 26
0
        public static bool ValidateAndCollect(IValidator validator, IValidationResults results)
        {
            IValidationResults validationResults = validator.Validate(results);

            return(validationResults.IsValid);
        }
Ejemplo n.º 27
0
 /// <summary>
 /// Validate data using data provided during initialization/construction.
 /// </summary>
 /// <returns></returns>
 public virtual IValidationResults Validate()
 {
     _lastValidationResults = new ValidationResults() as IValidationResults;
     Validate(Target, _lastValidationResults);
     return(_lastValidationResults);
 }
Ejemplo n.º 28
0
 private void ReplaceModelState(IValidationResults results)
 {
     ModelState.Clear();
     ModelState.Merge(results.AsModelStateDictionary);
 }
Ejemplo n.º 29
0
 /// <summary>
 /// Validate using the object provided.
 /// </summary>
 /// <param name="target"></param>
 /// <returns></returns>
 public virtual IValidationResults ValidateTarget(object target)
 {
     _lastValidationResults = new ValidationResults() as IValidationResults;
     Validate(new ValidationEvent(target, _lastValidationResults));
     return(_lastValidationResults);
 }
 /// <summary>
 /// Initialize the action context.
 /// </summary>
 /// <param name="item"></param>
 /// <param name="errorList"></param>
 /// <param name="messages"></param>
 public ImportExportActionContext(T item, IList <T> items, IValidationResults errors, IStatusResults messages)
     : base(item, errors, messages)
 {
     _items = items;
 }
Ejemplo n.º 31
0
 /// <summary>
 /// Validate using the results collection provided.
 /// </summary>
 /// <param name="results"></param>
 /// <returns></returns>
 public virtual IValidationResults Validate(IValidationResults results)
 {
     Validate(new ValidationEvent(Target, results));
     return(results);
 }
 /// <summary>
 /// Determines if text is either lowercase/uppercase alphabets or numbers.
 /// </summary>
 /// <param name="text">The text check</param>
 /// <param name="allowNull">Whether or not the text can be null</param>
 /// <param name="errors">List of errors.</param>
 /// <param name="tag">Tag used to identify the error.</param>
 /// <returns></returns>
 public static bool IsAlphaNumeric(string text, bool allowNull, IValidationResults errors, string tag)
 {
     return(CheckErrorRegEx(text, allowNull, RegexPatterns.AlphaNumeric, errors, tag, "Text supplied must only contain chars and numbers " + RegexPatterns.AlphaNumeric, null));
 }
Ejemplo n.º 33
0
 /// <summary>
 /// Initialize data.
 /// </summary>
 /// <param name="target"></param>
 /// <param name="useTarget"></param>
 /// <param name="results"></param>
 /// <param name="context"></param>
 public ValidationEvent(object target, IValidationResults results, object context)
 {
     Target  = target;
     Results = results;
     Context = context;
 }
        /// <summary>
        /// Determines if the date supplied is a date.
        /// </summary>
        /// <param name="text"></param>
        /// <param name="checkBounds"></param>
        /// <param name="minDate"></param>
        /// <param name="maxDate"></param>
        /// <returns></returns>
        public static bool IsDateWithinRange(string text, bool checkMinBound, bool checkMaxBound, DateTime minDate, DateTime maxDate, IValidationResults errors, string tag)
        {
            DateTime result = DateTime.MinValue;

            if (!DateTime.TryParse(text, out result))
            {
                errors.Add(tag, "Text supplied is not a valid date", null);
                return(false);
            }

            return(IsDateWithinRange(result, checkMinBound, checkMaxBound, minDate, maxDate, errors, tag));
        }
Ejemplo n.º 35
0
 /// <summary>
 /// Initialize data.
 /// </summary>
 /// <param name="target"></param>
 /// <param name="useTarget"></param>
 /// <param name="results"></param>
 /// <param name="context"></param>
 public ValidationEvent(object target, IValidationResults results)
 {
     Target  = target;
     Results = results;
 }
        /// <summary>
        /// Determines if the time string specified is a time of day. e.g. 9am
        /// and within the bounds specified.
        /// </summary>
        /// <param name="time"></param>
        /// <param name="checkBounds"></param>
        /// <param name="min"></param>
        /// <param name="max"></param>
        /// <returns></returns>
        public static bool IsTimeOfDayWithinRange(string time, bool checkMinBound, bool checkMaxBound, TimeSpan min, TimeSpan max, IValidationResults errors, string tag)
        {
            TimeSpan span = TimeSpan.MinValue;

            if (!TimeSpan.TryParse(time, out span))
            {
                return(CheckError(false, errors, tag, "Text supplied is not a valid time.", null));
            }

            return(IsTimeOfDayWithinRange(span, checkMinBound, checkMaxBound, min, max, errors, tag));
        }
Ejemplo n.º 37
0
 /// <summary>
 /// </summary>
 /// <param name="enumType"></param>
 /// <param name="val"></param>
 /// <param name="results"></param>
 /// <returns></returns>
 public static object GetValue(this EnumLookup lookup, Type enumType, string val, IValidationResults results)
 {
     return(GetValue(lookup, enumType, val, results, string.Empty));
 }
 /// <summary>
 /// Determines if the phone number supplied is a valid US phone number.
 /// </summary>
 /// <param name="phone"></param>
 /// <returns></returns>
 public static bool IsPhoneUS(string text, bool allowNull, IValidationResults errors, string tag)
 {
     return(CheckErrorRegEx(text, allowNull, RegexPatterns.PhoneUS, errors, tag, "Text supplied is not a valid US phone number.", null));
 }
Ejemplo n.º 39
0
        /// <summary>
        /// </summary>
        /// <param name="enumType"></param>
        /// <param name="val"></param>
        /// <param name="results"></param>
        /// <returns></returns>
        public static object GetValue(this EnumLookup lookup, Type enumType, string val, IValidationResults results, string defaultValue)
        {
            // Invalid enum value.
            if (!EnumLookup.IsValid(enumType, val))
            {
                results.Add("Invalid value '" + val + "' for " + enumType.Name);
                return(false);
            }

            return(EnumLookup.GetValue(enumType, val, defaultValue));
        }
Ejemplo n.º 40
0
 public void SetUp()
 {
     _validationResults = MockRepository.GenerateMock<IValidationResults>();
 }
 /// <summary>
 /// Initialize the action context.
 /// </summary>
 /// <param name="item"></param>
 /// <param name="errorList"></param>
 /// <param name="messages"></param>
 public ImportExportActionContext(T item, IList <T> items, IValidationResults errors)
     : base(item)
 {
     _items = items;
     Errors = errors;
 }
Ejemplo n.º 42
0
        /// <summary>
        /// Valdiates all the validation rules in the list.
        /// </summary>
        /// <param name="validationRules">List of validation rules to validate</param>
        /// <param name="validationErrors">List of validation results to populate.
        /// This list is populated with the errors from the validation rules.</param>
        /// <returns>True if all rules passed, false otherwise.</returns>
        public static bool Validate(IList<IValidator> validators, IValidationResults destinationResults)
        {
            if (validators == null || validators.Count == 0)
                return true;

            // Get the the initial error count;
            int initialErrorCount = destinationResults.Count;

            // Iterate through all the validation rules and validate them.
            foreach(IValidator validator in validators)
            {
                validator.Validate(destinationResults);
            }

            // Determine validity if errors were added to collection.
            return initialErrorCount == destinationResults.Count;
        }
Ejemplo n.º 43
0
 /// <summary>
 /// </summary>
 /// <param name="enumType"></param>
 /// <param name="val"></param>
 /// <param name="results"></param>
 /// <returns></returns>
 public static object GetValue(this EnumLookup lookup, Type enumType, string val, IValidationResults results)
 {
     return GetValue(lookup, enumType, val, results, string.Empty);
 }