New Posts New Posts RSS Feed: Validate sometimes null property
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Validate sometimes null property

 Post Reply Post Reply
Author
spudcud View Drop Down
Newbie
Newbie


Joined: 03-Nov-2011
Posts: 4
Post Options Post Options   Quote spudcud Quote  Post ReplyReply Direct Link To This Post Topic: Validate sometimes null property
    Posted: 08-Nov-2011 at 5:22am

I have a date property that is nullable in the database but based on business logic may not be null in specific cases. To accomplish this I figured inheriting a class from PropertyValueVerifier would be the best way. The VerifyValue method is called when the date is changed to another date but does not get called when the date goes to null. Is this a bug or am I doing something wrong?

 
...
return new NullEndDateVerifier(
   typeof(StatusRqst),
   EntityPropertyNames.EndDateTimeDt,
   null,
   true);
...

      public class NullEndDateVerifier : PropertyValueVerifier
      {
         public NullEndDateVerifier(
            Type a_entityType,
            string a_sPropertyName,
            string a_sDisplayName = null,
            bool? a_bShouldTreatEmptyStringAsNull = null)
            : base(new PropertyValueVerifierArgs(a_entityType, a_sPropertyName, false, a_sDisplayName, a_bShouldTreatEmptyStringAsNull))
         { }

         public NullEndDateVerifier(PropertyValueVerifierArgs a_verifierArgs)
            : base(a_verifierArgs)
         { }

         protected override VerifierResult VerifyValue(object itemToVerify, object valueToVerify, TriggerContext triggerContext, VerifierContext verifierContext)
         {
            return new VerifierResult(true);
         }
      }

 
Thanks,
Steve
Back to Top
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post Posted: 08-Nov-2011 at 7:33pm
Hi Steve;

You need to override the HandleNullPropertyValue method for nulls to be handled by the VerifyValue method.

// Can be overridden to return a custom null handling result or if null is returned,
// nulls will be handled by the VerifyValue method
protected override VerifierResult HandleNullPropertyValue(TriggerContext triggerContext, VerifierContext verifierContext) { 
    return null;
}
Back to Top
spudcud View Drop Down
Newbie
Newbie


Joined: 03-Nov-2011
Posts: 4
Post Options Post Options   Quote spudcud Quote  Post ReplyReply Direct Link To This Post Posted: 09-Nov-2011 at 4:56am
Denis,
 
Works perfectly.
 
Thanks,
 
Steve
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down