New Posts New Posts RSS Feed: Instance Verification
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Instance Verification

 Post Reply Post Reply
Author
Darren View Drop Down
Newbie
Newbie
Avatar

Joined: 06-Jul-2007
Location: United Kingdom
Posts: 23
Post Options Post Options   Quote Darren Quote  Post ReplyReply Direct Link To This Post Topic: Instance Verification
    Posted: 16-Jul-2007 at 9:07am

Just now i have implemeted custom property verfication into my developer classes.

For example i have implemented custom verifiers on the Username and Password, Forename , Surname and Age.
 
This works fine when the user tries to leave the field blank and they get the error icon appearing to the right of the textbox.
 
But when they add a new user, the fields are all blank at this point and they can save a blank record without verification firing.
 
I know i have to add something into the save event to trigger the verification. The question is what do i add into that event.
 
I have looked at the code from the tutorial , but i got lost in c# code.
 
Any pointers would much appreciated.
 
Thanks
 
 
Back to Top
eileenv View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 15-Jun-2007
Location: United States
Posts: 67
Post Options Post Options   Quote eileenv Quote  Post ReplyReply Direct Link To This Post Posted: 17-Jul-2007 at 12:19pm
In your Saving event handler, you can iterate through the list of entities and call instance verification on each entity. If errors are found you may want want to collect the error descriptions and throw an exception.
 
For example:
 
    protected virtual void SavingHandler(object sender, EntitySavingEventArgs e) {
      VerifyEntities(e.Entities);
    }
 
     private void VerifyEntities(IList<Entity> pEntities) {
      foreach ( Entity anEntity in pEntities ) {
        VerifierResultCollection results;
        results = aPm.VerifierEngine.Execute(pEntity);
        if ( !results.AreOk ) {
          // do something, e.g. get error descriptions and throw exception
        }
      }
    }
 
 


Edited by eileenv - 17-Jul-2007 at 5:44pm
Back to Top
Darren View Drop Down
Newbie
Newbie
Avatar

Joined: 06-Jul-2007
Location: United Kingdom
Posts: 23
Post Options Post Options   Quote Darren Quote  Post ReplyReply Direct Link To This Post Posted: 18-Jul-2007 at 3:07am

Thank you eileenv,

got it working before you posted , but thanks anyway.
My code is very similar to your snippet you posted.
 
Cheers
Back to Top
owais,zahid View Drop Down
Newbie
Newbie
Avatar

Joined: 22-Aug-2007
Location: Pakistan
Posts: 8
Post Options Post Options   Quote owais,zahid Quote  Post ReplyReply Direct Link To This Post Posted: 22-Aug-2007 at 7:33am

Yes, the above snippet works well. But we can do one more thing here. Suppose in a situation where you have many verifiers and you don't want all of them to be invoke. We can selectively invoke the verifiers that we need. By:

result = persistenceManager.VerifierEngine.Execute(code, EntityPropertyDescriptors.APBankCode.Code.PropertyPath);
 
 
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down