Am working on a site where members will need to activate their account before they can log in.
I've created my own custom identity (based on PTIdentity) by adding a new property: DateActivate.
I know I can just add a 'where' clause to check if the member is active in the db, but I would like to inform them that their account is inactive.
From what I've read, I need to make my Identity class inherit from BusinessBase instead of ReadOnlyBase, and add a rule to check that DateActive is not empty.
Since the private fields in my custom identity class would be populated in the fetch method, how would I trigger the error checking?
I'm hoping I'm going about it the right way. Would appreciate someone's input.
Thanks,
- Andy
Rocky,
Did like you suggested and my validation methods get called, but I do not get any exceptions raised even after my methods return false.
As fas as I know, I do not need to raise the exception myself, but I might be wrong.
Here is what I have:
Public Class CommunityIdentity
'Inherits ReadOnlyBase(Of CommunityIdentity)
Inherits BusinessBase(Of CommunityIdentity)
Protected Overrides Sub AddBusinessRules()
ValidationRules.AddRule(Of CommunityIdentity)(AddressOf AccountNotDeleted, "DateDeleted", 10)
End Sub
Private Shared Function AccountNotDeleted(Of T As CommunityIdentity)(ByVal target As T, ByVal e As Validation.RuleArgs) As Boolean
If Not (target.DateDeleted.IsEmpty) Then
e.Description = My.Resources.MemberAccount_Deleted
Return False
Else
Return True
End If
End Function
Where are you expecting an exception? CheckRules() doesn't throw exceptions, it just puts the object into an invalid state if any rules are broken. You'd only get an exception when calling Save() on your root object. Save() throws a ValidationException if the object is in an invalid state.
Review Chapter 3 for more details on how this works. Or Chapters 9 and 10 to see how the validation rules are used in Windows and Web UIs.
Rocky,
I will review chapter 3, but based on your explanation and examples I think I understand how it works.
What I would like to happen is that when I set the values from the db to my object if the member has been marked as deleted in the db, that I would get an exception, which I can then pass up to the principal class and then to the gui. Would I need the Get method to check the object that was fetched and raise an exception if is invalid???
On a similiar note, there will be several times when I need to validate input information (the username) before I query a member. I would like to call a Get factory method and get an exception raised if the username is not of valid format. Would I need to raise my own exception since I would not be calling Save()?
Copyright (c) Marimer LLC