CSLA .NET

Vibrant discussion about CSLA .NET and using the framework to build great business applications.

Csla PropertyStatus and AddInformationResult IsValid Property

rated by 0 users
Not Answered This post has 0 verified answers | 4 Replies | 2 Followers

Not Ranked
14 Posts
Kevin posted on Fri, Nov 25 2011 7:57 AM

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

All Replies

Top 10 Contributor
1,813 Posts

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.

Jonny Bekkum, Norway CslaContrib Coordinator

Not Ranked
14 Posts
Kevin replied on Mon, Nov 28 2011 2:13 AM

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.

Top 10 Contributor
1,813 Posts

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.

Jonny Bekkum, Norway CslaContrib Coordinator

Top 150 Contributor
59 Posts

JonnyBee:
Unfortunately the IsValid property setter is private so you can't set it even if you override the UpdateState method.

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

  1. RuleSeverity=Error to define something that blocks the user from saving data (data IsValid to save). 
  2. RuleSeverity=Warning to define an edge case that might just be a typo by the user. E.g. Date not close enough to today's date.
  3. RuleSeverity=Info - Never used.
            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

Jamie Clayton
Senior Application Developer

Website: Jenasys Design - Australia
Blog: Practical CSLA

Page 1 of 1 (5 items) | RSS

Copyright (c) 2006-2010 Marimer LLC. All rights reserved.
Email admin@lhotka.net for support.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems