Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Event handling in business objects
Message
From
26/06/2008 14:59:16
 
 
To
25/06/2008 16:23:55
Timothy Bryan
Sharpline Consultants
Conroe, Texas, United States
General information
Forum:
ASP.NET
Category:
The Mere Mortals .NET Framework
Miscellaneous
Thread ID:
01326692
Message ID:
01327015
Views:
12
I think I have it mostly figured out now. Will just have to do some testing later on.

My code now adds a 'broken rule' to the business object if the delete will fail on a FK constraint.
       /// <summary>
        /// Checks for possible FK constraint violations prior to deleting a record
        /// If return is FALSE the delete is aborted
        /// </summary>
        /// <param name="entity"></param>
        /// <returns>bool</returns>
        protected override bool HookPreDeleteEntity(SQLTracGrpEntity entity)
        {

            bool bReturn = base.HookPreDeleteEntity(entity);

            if (bReturn)
            {
                // check to see if this type is used by a group or resource
                string sCommand = "[dbo].[sp_SQLTrac_CanDeleteGrp]";

                if ((int)this.ExecSprocScalar(sCommand, this.CreateParameter("@GrpID", (object)entity.GrpID, DbType.Int16)) == 0 )
                {
                    this.Rules.EntityPropertyDisplayName = "Group - "+entity.GrpName;

                    string sMsg = "Unable to delete " + this.Rules.EntityPropertyDisplayName;
                    sMsg += ".  This group is contains resource entries and/or child groups.";


                    this.Rules.AddErrorProviderBrokenRule("GrpName", sMsg);
                    
                    bReturn = false;
                }



            }

            return bReturn;
        }
So if the DeleteEntity() method returns a false, I can check the rules collection and pick up the message.

Tim
Previous
Reply
Map
View

Click here to load this message in the networking platform