Пример #1
0
        /// <summary>
        /// Removes the business rule validation result.
        /// </summary>
        /// <param name="businessRuleValidationResult">The business rule validation result.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="businessRuleValidationResult"/> is <c>null</c>.</exception>
        public void Remove(IBusinessRuleValidationResult businessRuleValidationResult)
        {
            Argument.IsNotNull("businessRuleValidationResult", businessRuleValidationResult);

            lock (_businessRuleValidations)
            {
                _businessRuleValidations.Remove(businessRuleValidationResult);

                UpdateLastModificationStamp(FastDateTime.Now);
            }
        }
        /// <summary>
        /// Adds the business rule validation result.
        /// <para />
        /// This method is great to add asynchronous validation.
        /// </summary>
        /// <param name="modelValidation">The model validation.</param>
        /// <param name="businessRuleValidationResult">The business rule validation result.</param>
        /// <param name="validate">if set to <c>true</c>, this method call will immediately force a call to validate the model.</param>
        public static void AddBusinessRuleValidationResult(this IModelValidation modelValidation, IBusinessRuleValidationResult businessRuleValidationResult, bool validate = false)
        {
            Argument.IsNotNull(() => modelValidation);
            Argument.IsNotNull(() => businessRuleValidationResult);

            EventHandler<ValidationEventArgs> validating = null;
            validating = (sender, e) =>
            {
                modelValidation.Validating -= validating;
                e.ValidationContext.AddBusinessRuleValidationResult(businessRuleValidationResult);
            };

            modelValidation.Validating += validating;

            if (validate)
            {
                modelValidation.Validate(true);
            }
        }
Пример #3
0
        /// <summary>
        /// Sets the business rule validation result.
        /// </summary>
        /// <param name="validationResult">The business rule validation result.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="validationResult"/> is <c>null</c>.</exception>
        protected void SetBusinessRuleValidationResult(IBusinessRuleValidationResult validationResult)
        {
            Argument.IsNotNull("validationResult", validationResult);

            if (string.IsNullOrEmpty(validationResult.Message))
            {
                return;
            }

            var previousValidations = _internalValidationContext.GetBusinessRuleValidations();

            // First, check if the same error already exists
            bool alreadyExists = (from previousFieldValidation in previousValidations
                                  where string.Compare(previousFieldValidation.Message, validationResult.Message) == 0
                                  select previousFieldValidation).Any();

            if (alreadyExists)
            {
                return;
            }

            _internalValidationContext.AddBusinessRuleValidationResult(validationResult);

            if (!IsValidating)
            {
                switch (validationResult.ValidationResultType)
                {
                case ValidationResultType.Warning:
                    NotifyWarningsChanged(string.Empty, true);
                    break;

                case ValidationResultType.Error:
                    NotifyErrorsChanged(string.Empty, true);
                    break;
                }
            }
        }
Пример #4
0
 protected void SetBusinessRuleValidationResult(IBusinessRuleValidationResult validationResult)
 {
     throw new NotSupportedException();
 }
Пример #5
0
        /// <summary>
        /// Removes the business rule validation result.
        /// </summary>
        /// <param name="businessRuleValidationResult">The business rule validation result.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="businessRuleValidationResult"/> is <c>null</c>.</exception>
        public void RemoveBusinessRuleValidationResult(IBusinessRuleValidationResult businessRuleValidationResult)
        {
            Argument.IsNotNull("businessRuleValidationResult", businessRuleValidationResult);

            lock (_businessRuleValidations)
            {
                _businessRuleValidations.Remove(businessRuleValidationResult);

                UpdateLastModificationStamp(DateTime.Now);
            }
        }
Пример #6
0
 public void RemoveBusinessRuleValidationResult(IBusinessRuleValidationResult businessRuleValidationResult)
 {
     Remove(businessRuleValidationResult);
 }
Пример #7
0
 public void AddBusinessRuleValidationResult(IBusinessRuleValidationResult businessRuleValidationResult)
 {
     Add(businessRuleValidationResult);
 }
Пример #8
0
        /// <summary>
        /// Sets the business rule validation result.
        /// </summary>
        /// <param name="validationResult">The business rule validation result.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="validationResult"/> is <c>null</c>.</exception>
        protected void SetBusinessRuleValidationResult(IBusinessRuleValidationResult validationResult)
        {
            Argument.IsNotNull("validationResult", validationResult);

            if (string.IsNullOrEmpty(validationResult.Message))
            {
                return;
            }

            var previousValidations = _internalValidationContext.GetBusinessRuleValidations();

            // First, check if the same error already exists
            bool alreadyExists = (from previousFieldValidation in previousValidations
                                  where string.Compare(previousFieldValidation.Message, validationResult.Message) == 0
                                  select previousFieldValidation).Any();
            if (alreadyExists)
            {
                return;
            }

            _internalValidationContext.AddBusinessRuleValidationResult(validationResult);

            if (!IsValidating)
            {
                switch (validationResult.ValidationResultType)
                {
                    case ValidationResultType.Warning:
                        NotifyWarningsChanged(string.Empty, true);
                        break;

                    case ValidationResultType.Error:
                        NotifyErrorsChanged(string.Empty, true);
                        break;
                }
            }
        }
Пример #9
0
        /// <summary>
        /// Adds the business rule validation result.
        /// <para />
        /// This method is great to add asynchronous validation.
        /// </summary>
        /// <param name="modelValidation">The model validation.</param>
        /// <param name="businessRuleValidationResult">The business rule validation result.</param>
        /// <param name="validate">if set to <c>true</c>, this method call will immediately force a call to validate the model.</param>
        public static void AddBusinessRuleValidationResult(this IModelValidation modelValidation, IBusinessRuleValidationResult businessRuleValidationResult, bool validate = false)
        {
            Argument.IsNotNull("modelValidation", modelValidation);
            Argument.IsNotNull("businessRuleValidationResult", businessRuleValidationResult);

            EventHandler <ValidationEventArgs> validating = null;

            validating = (sender, e) =>
            {
                modelValidation.Validating -= validating;
                e.ValidationContext.AddBusinessRuleValidationResult(businessRuleValidationResult);
            };

            modelValidation.Validating += validating;

            if (validate)
            {
                modelValidation.Validate(true);
            }
        }