I am using CSLA 184.108.40.206. I have one instance - On edit of an object does not permit users to edit certain properties in accordance with the value of another property . For example there is an object Person with properties Name, age,active. If a person want to edit person details he will load the person to win form. But i have to create a rule which checks the value of active ( true,false). if true allow the user to edit details of person else dont permit him to do so and show some prompt like the error provider
You could do this as a business rule, where your description would be that they cannot edit this field but this would still allow them make changes and they would have to manually correct them and you would need to hold the original values so you had something to compare them to know if they had been changed back. I wouldn't recommend this option unless you wanted people to edit values which isn't what I think you want to achieve.
The better option is to override the CanWriteProperty method and for the properities in question check your active flag and return false when required, this would prevent any changes occurring to those properties. You would then need to disable or make read-only those fields on the UI to prevent data-binding issues (assuming you are using data-bindings).
There is a control included as part of CSLA called the ReadWriteAuthorization control that can do this for you (disable controls that don't have write access), or you can do it manually for each control by checking the CanWriteProperty method in your GUI.
The method may look like this:
Protected Overrides CanWriteProperty(ByVal PropertyName as String) As Boolean
If Me.Active = False Then
If PropertyName = "Age" OrElse PropertyName = "Name" Then
Thanks for the reply
Actually the non editable field includes not only Name and age but also the 'Active' too.
After the event 'Fetch' , if i can do something like this
Step1 : Check the value of the Active of Current object
Step 2: If true disable/ non writable all properties
Step 3: if false Enable/writable all controls
Can i use/ create some thing like what we call after Fetch 'ValidationRules.CheckRules()' for Authorization mechanism
Waiting for your reply
You'd be able to do something like what you want with authorization rules in the new CSLA 4 (from my understanding, haven't used it yet).
However, you can still use the CanWriteProperty method described above, you'll just need to customize it to include whatever properities you want disabled whenever the active flag is false; even if this includes in the active flag itself.
The only thing I would suggest is that if the user can change the active flag and fields should still be editable at that time until it is fetched again, you may also want to include the IsDirty flag in your check or have an internal variable that holds the original state of the Active flag at the time of creation/fetch that is never changed and use that instead.
I also read about the new features in CSLA 4 but as I am not in a position to change my version from the live software.
But Thanks For the quick reply let me work out something on that
In one more problem you can help me
I have classes Person --> PersonRoles --> PersonRole
The personRoles List class is bound to a gridview. There are three fields that can be edited in the PersonRole grid view that is RoleType, StartDate, EndDate and Active
If a user want to deactivate a role of a person he should set EndDate to today and Active to 'N' .
I can Override CanWriteProperty in PersonRole class and write rules for setting the values
But one of the rule is that i should check the person's Primary role , which is inside the Class Person
Can you tell me how can i check a property value of the Parent class in its child classes?
Copyright (c) Marimer LLC