CSLA .NET

Vibrant discussion about CSLA .NET and using the framework to build great business applications.

ValidationRule not firing up when calling SetProperty (xxxxxProperty ) in CSLA 3.8

rated by 0 users
Answered (Verified) This post has 1 verified answer | 1 Reply | 1 Follower

Top 500 Contributor
35 Posts
Lord02 posted on Tue, Sep 25 2012 9:00 AM

Hi Lhotka,

Could you please explain something to me ...

A rule I created is NOT firing up when I change the property which the rule is set on,

the problem is that calling this:   SetProperty(userEntryProperty, value);
does NOT fire up the rule ???! 

Example:

This is the class declaration ( the LogOnCredentials then inherits from BusinessBase<T> )
[Serializable]
    public class UserVerificationCredentials : LogOnCredentials<UserVerificationCredentials>

 

The csla-variable & Property look like this:

private static PropertyInfo<string> userEntryProperty = RegisterProperty<string>(c => c.UserEntry);
 
        public string UserEntry
        {
            get
            {
                return GetProperty(userEntryProperty);
            }
            set
            {
                SetProperty(userEntryProperty, value);
            }
        }

And it's wired up like this ( and this runs when the object is created in the static constructor ):
internal static UserVerificationCredentials NewUserVerificationCredentials()
        {
            return DataPortal.Create<UserVerificationCredentials>();
        }
        
        #endregion
        #region  Data Access
 
        /// <summary>
        /// Called by the dataportal for Create operations.
        /// </summary>
        /// <remarks>
        /// Runs on the dataportal layer if available.
        /// </remarks>
        [RunLocal]
        protected override void DataPortal_Create()
        {
            using (BypassPropertyChecks)
            {
                // Set properties tat
                // TODO: Evaluate fetching from HTTP context
                ValidationRules.CheckRules();
            }
        }
        #endregion

 /// <summary>
        /// Adds the business rules.
        /// </summary>
        protected override void AddBusinessRules()
        {
            ValidationRules.AddDataAnnotations();
            base.AddBusinessRules();
 
            ValidationRules.AddRule<UserVerificationCredentials>(UserEntryRule, userEntryProperty, 0);
        }



And this is the actual rule:
private static bool UserEntryRule<T>(T target, RuleArgs e) where T : UserVerificationCredentials
        {
            bool result = true;
            if (string.IsNullOrEmpty(target.ReadProperty(userEntryProperty)) == false)
            {
                // It should only be valid to enter a user entry when the 
                // control has already been activated.
                result = target.HasBeenActivatedByUser;
                e.Description = Resources.BusinessResources.SmsCodeRequired;
                e.Severity = RuleSeverity.Error;
            }
 
            return result;
        }

Do you have any idea why the rule is NOT being fired up when calling the:
SetProperty(userEntryProperty, value);    ???

Kind regards,
EE.
 

Answered (Verified) Verified Answer

Top 500 Contributor
35 Posts
Answered (Verified) Lord02 replied on Tue, Sep 25 2012 9:24 AM
Verified by Lord02

Nevermind ... I found out what the problem was.

The value was the same as before, hence the rule doesn't fire up! ;-)

rgd,

EE.

Page 1 of 1 (2 items) | RSS

Copyright (c) 2006-2010 Marimer LLC. All rights reserved.
Email admin@lhotka.net for support.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems