Hello,
I've got a business rule that checks if a value already exists in my database. This rules works fine and will add the correct information:
if (e.Object.Exists)
{
context.AddInformationResult("Already exists");
}
context.Complete();
In my BO it looks like this:
BusinessRules.AddRule(new CustomRules.ArztNummerExists(ArztNummerProperty, FilialeUidProperty, UIDProperty));
In my View (XAML Code) I've a CSLA PropertyStatus that's binded to my "ArztNummerProperty". Works fine.
If my rule doesn't add a information result to the context, the PropertyStatus is valid, but if my rule adds the information result to the context, my PropertyStaus is not valid.
How can I say to my PropertyStatus that the IsValid Property should be true in this case? The information is visible on my GUI - works fine.
Or is there something I'm missunterstand?
Hopefully you guys understand everything :-)
Kind regards
Kevin
Hi Kevin,
PropertyStatus is build so that it will show Error/Warning/Info message and the IsValid property on the Propertystatus control is set to false if there is any broken rule on the field.
I don't know if that s a bug or intentional.
I hope Rocky can assist with an answer to that.
Theproperty is set in UpdateState method of PropertyStatus:
IsValid = BrokenRules.Count == 0;
If following the traditional rules for IsValid on a business object that code line should be:
IsValid = BrokenRules.Any(p => p.Severity == RuleSeverity.Error);
Unfortunately the IsValid property setter is private so you can't set it even if you override the UpdateState method.
Thank you JonnyBee. That explains everything.
I also think, the IsValid Property should be IsValid = TRUE if there is an information or warning severity.
@Rocky: Yes, it would be really nice If you can assist with an answer to that.
Hi Kevin,
Issuecreated in BugTracker: http://www.lhotka.net/cslabugs/edit_bug.aspx?id=992
We will consider changing how IsValid is updated in Csla 4.3.
In VB.net I've been Overriding the IsValid property in my Business Objects to overcome the definition of BrokenRule including all RuleSeverity options. I use the following convention
Public Overrides ReadOnly Property IsValid() As Boolean Get ' Linq Edition Return (From item In BrokenRulesCollection Where item.Severity = RuleSeverity.Error).Count = 0 ' TODO: Lambda edition ?? VB. Determine the lambda version of the loop below 'Return BrokenRulesCollection.Any( p >= p.Severity = RuleSeverity.Error) ' GOLE: Good old Loop edition 'Dim result As Boolean = True 'For Each item As BrokenRule In BrokenRulesCollection ' If item.Severity = RuleSeverity.Error Then ' result = False ' End If 'Next 'Return False End Get End Property
Copyright (c) Marimer LLC