Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
UI or BO code?
Message
From
25/08/2010 08:56:01
 
 
To
24/08/2010 23:29:56
Timothy Bryan
Sharpline Consultants
Conroe, Texas, United States
General information
Forum:
ASP.NET
Category:
The Mere Mortals .NET Framework
Title:
Miscellaneous
Thread ID:
01478134
Message ID:
01478322
Views:
21
>>>Tim
>>
>>Originally I was planning on saving the changes in a separate table as I thought it was just an audit trail needed, but it definitely makes more sense keeping the changes/history in one table.
>>
>>I'm afraid that I need a bit more help with the specifics.
>>
>>When you say "do that on the retrieval", what method would you suggest? I was thinking the HookPostGetEvent() would be ideal, but what code do I use in there to create the new entity and return that instead of the one that has already been created?
>>
>>Whether or not they save the new record should have no effect on the original record.
>>
>>With respect to what I tried that didn't work, can you explain why it didn't? I had used this code:
>>
>>
        protected override void HookPostGetEntity(PolicyEntity policyEntity)
>>        {
>>            // check if the entity's status is not "Pending"
>>            if (policyEntity.StatusFK != (int)StatusCode.Pending)
>>            {
>>                // if so, then convert the entity to be a "new" record
>>                this.CallStateChange(mmBusinessState.Adding);
>>                policyEntity.PolicyPK = Guid.NewGuid();
>>            }
>>        }
>>
>>then when I saved I got a message about the update statement not affecting any of the expected rows. If I had changed the state to Adding, why was it doing an update and not an Insert?
>
>Hi Frank,
>
>What is wrong with putting this in your main retrieval method? Do you have a public method that you are calling on your business object to get the specified policy? That method could be self contained with getting the specified entity, checking the status, then creating a new entity with the changes you need and returning it instead. There is no need to use a hook method when you are calling some method to retrieve the entity in the first place. This would work best because you are retrieving a new entity, setting the values and then *It* is the current entity on the business object so you can bind to it normally and save it normally.
>Tim

Hi Tim,

I have absolutely no opinion about where to put it. The VFP framework I use recommends using hook methods where possible and has a whole heap of them so that is where I first looked.

What do you mean by "my main retrieval method"? Do you mean this:
        public PolicyEntity GetPolicyByPolicyPK(Guid policyPK)
        {
            return this.GetEntity("PoliciesSelectByPK",
                this.CreateParameter("@PolicyPK", policyPK));

        }
If so, I guess something like this is what you are recommending?
// get the requested entity
PolicyEntity oPolicyEntity = this.GetEntity("PoliciesSelectByPK",
                this.CreateParameter("@PolicyPK", policyPK));
// check its status
if (oPolicyEntity.Status == "Pending")
   {
      // if it is not Pending then create a new entity, copy the data from the original entity 
      PolicyEntity oNewPolicyEntity = new PolicyEntity();
      CopyPolicyEntity(oPolicyEntity, oNewPolicyEntity);
      // return the new entity
      return oNewPolicyEntity;
   }
else
   return oPolicyEntity;
Frank.

Frank Cazabon
Samaan Systems Ltd.
www.samaansystems.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform