Example #1
0
 /// <summary>
 /// Cheks the Rules Violations on the given <see cref="IModelEntity"/>. If rules violations exist,
 /// a <see cref="RulesViolationsException"/> is thrown.
 /// </summary>
 /// <param name="modelEntity">The model entity.</param>
 /// <exception cref="RulesViolationsException">
 /// Thrown if rules violations exist.
 /// </exception>
 public static void CheckRulesViolations(this IModelEntity modelEntity)
 {
     if (!modelEntity.IsValid())
     {
         throw new RulesViolationsException("Rule violations prevent saving", modelEntity.GetRuleViolations());
     }
 }
Example #2
0
 public static void AddRulesViolations(this ModelStateDictionary modelState, IModelEntity modelEntity)
 {
     foreach (RuleViolation issue in modelEntity.GetRuleViolations())
     {
         modelState.AddModelError(issue.PropertyName, issue.ErrorMessage);
     }
 }
Example #3
0
 /// <summary>
 /// Determines wheather the <see cref="IModelEntity"/> instance is valid (without business rules
 /// violations).
 /// </summary>
 /// <param name="modelEntity">The <see cref="IModelEntity"/> that this method extends.</param>
 /// <returns>
 /// <c>true</c>if <paramref name="modelEntity"/> instance is valid; otherwise, <c>false</c>.
 /// </returns>
 public static bool IsValid(this IModelEntity modelEntity)
 {
     return(modelEntity.GetRuleViolations().GetEnumerator().MoveNext() == false);
 }