New Posts New Posts RSS Feed: When will the custom description be used?
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

When will the custom description be used?

 Post Reply Post Reply
Author
LesleySastro View Drop Down
Newbie
Newbie


Joined: 13-Nov-2008
Posts: 9
Post Options Post Options   Quote LesleySastro Quote  Post ReplyReply Direct Link To This Post Topic: When will the custom description be used?
    Posted: 05-Oct-2009 at 8:11am
I have the following custom verifier (see below). The idea is that the IdentificationNumberEntityProperty is required under certain conditions. The custom description I wrote is never used. Any ideas why? 

#region Identification Number

private class IdentificationNumberRequiredVerifier : PropertyValueVerifier<AccountMutation>

{

public IdentificationNumberRequiredVerifier()

: base ( new PropertyValueVerifierArgs<AccountMutation>(

IdentificationNumberEntityProperty.Name, true, "Identification Number"))

{

ExecutionModes = VerifierExecutionModes.InstanceAndOnPostsetTriggers;

}

protected override VerifierResult VerifyValue(object itemToVerify, object valueToVerify,

TriggerContext triggerContext, VerifierContext verifierContext)

{

if ((itemToVerify is AccountMutation) && (

(((AccountMutation)itemToVerify).Action == 1) || // New Account

(((AccountMutation)itemToVerify).Action == 2) || // Change Personal Info

(((AccountMutation)itemToVerify).Action == 5) || // Change All Info

(((AccountMutation)itemToVerify).Action == 7))) // Reactivate Account

{

if ((valueToVerify == null) || (string.IsNullOrEmpty(valueToVerify.ToString().Trim())))

return new VerifierResult(false, Description);

}

return new VerifierResult(true);

}

protected override VerifierResult VerifyValueTyped(AccountMutation itemToVerify, object valueToVerify,

TriggerContext triggerContext, VerifierContext verifierContext)

{

return VerifyValue(itemToVerify, valueToVerify, triggerContext, verifierContext);

}

public override string Description

{

get

{

// TODO Localize

return "Identification Number is required. ***";

}

}

}

#endregion

Back to Top
GregD View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 374
Post Options Post Options   Quote GregD Quote  Post ReplyReply Direct Link To This Post Posted: 06-Oct-2009 at 7:09pm
I took your code and tweaked it into a Country verifier for the Customer entity of NorthwindIB. Any subsequent attempt to set the Country property to null (regardless of the value of the Action property) elicited a generic "Country is required" message (not your custom message).

So I set a break point inside your VerifyValue() method and found that it never runs. The null check is simply resulting from the true setting on the second parameter of your call to the PropertyValueVerifierArgs constructor):


public IdentificationNumberRequiredVerifier()

: base ( new PropertyValueVerifierArgs<AccountMutation>(

IdentificationNumberEntityProperty.Name, true, "Identification Number"))



Back to Top
LesleySastro View Drop Down
Newbie
Newbie


Joined: 13-Nov-2008
Posts: 9
Post Options Post Options   Quote LesleySastro Quote  Post ReplyReply Direct Link To This Post Posted: 07-Oct-2009 at 8:54am
Thanks Greg, I suspected that already. Setting the parameter to false will not help either, because the verifier will not run when the property is null, only when a value is entered for that property. So the big question is how to create a custom required verifier (one that will display my custom error message). For example, in your test when the country is USA the state should be a required property.
Back to Top
GregD View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 374
Post Options Post Options   Quote GregD Quote  Post ReplyReply Direct Link To This Post Posted: 07-Oct-2009 at 6:50pm
You can do just about anything with a delegate verifier. Here's one that makes the Title for an Employee required if the provided FirstName is less than two characters long.  (I modified the delegate verifier example from the Code Samples in the Validation topic.)

    #region Conditional Required Verifier

    private static Verifier TitleRequiredIfFirstNameIsShort() {
      string description = "A Title is required if the first name is shorter than two characters.";
      DelegateVerifier<Employee> v =
        new DelegateVerifier<Employee>(description, TitleRequiredCondition);
      v.AddTrigger(Employee.TitleEntityProperty.Name);
      v.ExecutionModes = VerifierExecutionModes.InstanceAndOnPostsetTriggers;
      return v;
    }

    private static VerifierResult TitleRequiredCondition(
      Employee pEmp, TriggerContext pTriggerContext,
      VerifierContext pVerifierContext) {

      if (pTriggerContext != null &&
        // We are not checking the proposed value because don't expect to call it preset
        pTriggerContext.Timing == TriggerTiming.Preset) {
        throw new VerifierException("TitleRequired verifier not implemented for Preset");
      }
      bool isValid = true;
      if (pEmp.FirstName.Length < 2 && pEmp.Title == null) {
        isValid = false;
      }
      return new VerifierResult(isValid);
    }

    #endregion

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down