/// <summary>
 /// Throws a validation exception if any of the properties don't validate
 /// </summary>
 /// <param name="model"></param>
 public void Validate(object model)
 {
     IValidationProvider validator = new ActiveRecordValidator(model);
     if( validator.IsValid() ) return;
     throw new ModelValidationException(new ActiveRecordValidationErrorsCollectionAdapter(validator));
 }
Exemplo n.º 2
0
 /// <summary>
 /// Throws an exception explaining why the save or update
 /// cannot be executed when fields are not ok to pass.
 /// </summary>
 /// <remarks>
 /// You can override this method to declare a better behavior.
 /// </remarks>
 /// <remarks>Forwards the call to <see cref="ActualValidator"/>.</remarks>
 protected virtual void OnNotValid()
 {
     ActiveRecordValidator.ThrowNotValidException(ValidationErrorMessages, PropertiesValidationErrorMessages);
 }
        /// <summary>
        /// Returns the list of invalid property errors for the model
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public IValidationErrorsCollection GetValidationErrors(object model)
        {
            IValidationProvider validator = new ActiveRecordValidator(model);

            return validator.IsValid() ? new ValidationErrorsCollectionCollection() : new ActiveRecordValidationErrorsCollectionAdapter(validator);
        }