Custom Validation/BL Template

Posts   
 
    
jvidal
User
Posts: 37
Joined: 17-Sep-2007
# Posted on: 21-Apr-2008 13:04:52   

Hi

I'm using SelfServicing general, and I'd like to add some bussiness logic to the Entities generated, like everytime the entity is saved automatically set the lastupdate field of the entity with the current date or if saving an entity without Guid then automatically set the field, all this should be done before persiting the entity.

Its there any Custom Template designed for this matter where I should put this logic?, or should I overrride the original Template for Selfservicing, if so, in which method should I add this logic...

The TDL sintax will be something like this:

<[Foreach EntityField ]>
<[If StringValueEquals EntityFieldName "LastUpdate"]> this.LastUpdate = DataTime.Now; <[EndIf]> <[NextForeach]>

<[Foreach EntityField ]>
<[If StringValueEquals EntityFieldName "Guid"]> if (this.Guid == String.Empty) { this.Guid = "abcsaddddssddetc..."; } <[EndIf]> <[NextForeach]>

Please advice what it is in your opinion the best way to implement this?

PS> I can't use SPs on my DB...cry

Many Thanks Jaume

goose avatar
goose
User
Posts: 392
Joined: 06-Aug-2007
# Posted on: 21-Apr-2008 18:17:48   

Jaume, Have you seen LLBLGen Auditing mechanism? I would use an Auditor class injected to all the classes.

jvidal
User
Posts: 37
Joined: 17-Sep-2007
# Posted on: 22-Apr-2008 11:45:39   

Hi Goose

Thanks for you message.

I've had a look at the auditing, and I may do the job but are you sure this is the best way of doing this? Wouldn't it be better ovewriting the Selfservicing Entity Template, I say it becuase the auditing seems designed to do auditing instead of holding the bussiness rules/ default values, that I need...

Thanks Jaume

Walaa avatar
Walaa
Support Team
Posts: 14987
Joined: 21-Aug-2005
# Posted on: 22-Apr-2008 11:59:10   

For custom validation or validation logic you may use LLBLGen Pro Validation framework. Also Auditing might be used here.

Please check the following thread: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=11690

Another somehow relevant thread: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=11612

jvidal
User
Posts: 37
Joined: 17-Sep-2007
# Posted on: 22-Apr-2008 14:14:37   

Thanks Walla, this does the job,

Posted the code:

I've added this to the Custom_EntityTemplate


protected override void OnValidateEntityBeforeSave()
{
   <[Foreach EntityField ]><[If StringValueEquals EntityFieldName "Guid"]>
        if (this.Guid == String.Empty)
    {
         this.Guid =  System.Guid.NewGuid().ToString("N").ToLower(System.Globalization.CultureInfo.CurrentCulture);
    }
    <[EndIf]>
<[NextForeach]>
            
<[Foreach EntityField ]><[If StringValueEquals EntityFieldName "LastUpdate"]>
               this.LastUpdate = DateTime.Now;
<[EndIf]>
<[NextForeach]>
}

Posts: 1263
Joined: 10-Mar-2006
# Posted on: 26-Apr-2008 05:28:06   

So, you cannot use triggers on your database either?

jvidal
User
Posts: 37
Joined: 17-Sep-2007
# Posted on: 28-Apr-2008 10:55:05   

No, the db I'm using, SQL CE, doesn't allow triggers.