/// <summary>
        /// Method to perform validation on the model as a whole
        /// Applies changes to the validation store provided as a parameter
        /// </summary>
        /// <param name="editContext">The EditContext provided by the form doing the editing</param>
        /// <param name="messages">The validation message store to be updated during validation</param>
        private static void ValidateModel(EditContext editContext, ValidationMessageStore messages)
        {
            if (editContext.Model is ICheckRules model)
            {
                // Transfer broken rules of severity Error to the ValidationMessageStore
                messages.Clear();
                foreach (var brokenRuleNode in BusinessRules.GetAllBrokenRules(model))
                {
                    foreach (var brokenRule in brokenRuleNode.BrokenRules)
                    {
                        if (brokenRule.Severity == RuleSeverity.Error)
                        {
                            // Add a new message for each broken rule
                            messages.Add(new FieldIdentifier(brokenRuleNode.Object, brokenRule.Property), brokenRule.Description);
                        }
                    }
                }
            }

            // Inform consumers that the state may have changed
            editContext.NotifyValidationStateChanged();
        }
Beispiel #2
0
        /// <summary>
        /// Method to perform validation on the model as a whole
        /// Applies changes to the validation store provided as a parameter
        /// </summary>
        /// <param name="editContext">The EditContext provided by the form doing the editing</param>
        /// <param name="messages">The validation message store to be updated during validation</param>
        private static void ValidateModel(EditContext editContext, ValidationMessageStore messages)
        {
            ICheckRules model;

            // Get access to the model via the required interface
            model = editContext.Model as ICheckRules;

            // Check if the model was provided, and correctly cast
            if (editContext.Model == null)
            {
                throw new ArgumentNullException(nameof(editContext.Model));
            }
            if (model == null)
            {
                throw new ArgumentException(
                          string.Format(Csla.Properties.Resources.InterfaceNotImplementedException,
                                        nameof(editContext.Model), nameof(ICheckRules)));
            }

            // Transfer broken rules of severity Error to the ValidationMessageStore
            messages.Clear();
            foreach (var brokenRuleNode in BusinessRules.GetAllBrokenRules(model))
            {
                foreach (var brokenRule in brokenRuleNode.BrokenRules)
                {
                    if (brokenRule.Severity == RuleSeverity.Error)
                    {
                        // Add a new message for each broken rule
                        messages.Add(new FieldIdentifier(brokenRuleNode.Object, brokenRule.Property), brokenRule.Description);
                    }
                }
            }

            // Inform consumers that the state may have changed
            editContext.NotifyValidationStateChanged();
        }
Beispiel #3
0
 public virtual BrokenRulesTree GetAllBrokenRules()
 {
     return(BusinessRules.GetAllBrokenRules(this, false));
 }