Require at least one property

Require at least one property

Old forum URL: forums.lhotka.net/forums/t/9876.aspx


AaronH posted on Thursday, December 16, 2010

Hi,

I am using a business object as search criteria within the client.  I want at least one property to be supplied by the user before they can perform a search.  I have a search button (IsEnabled) that is bound to the IsValid property of the business object.

Is there a good example of how to require that at least one property is supplied in order for it to be valid?

Thanks!

RockfordLhotka replied on Thursday, December 16, 2010

Which version of CSLA?

AaronH replied on Friday, December 17, 2010

4.0

RockfordLhotka replied on Friday, December 17, 2010

If all you care about is having IsValid be false, I'd create an object-level business rule (a rule not attached to a specfic property) that checks to see if at least one property has a value. Then in OnPropertyChanged call BusinessRules.CheckObjectRules to run this rule every time a property changes.

protected override void OnPropertyChanged(string name)
{
  base.OnPropertyChanged(name);
  BusinessRules.CheckObjectRules();
}

 

Copyright (c) Marimer LLC