Where to place Save logic?

Posts   
 
    
gabrielk avatar
gabrielk
User
Posts: 231
Joined: 01-Feb-2005
# Posted on: 03-Mar-2005 17:06:16   

Hi Folks,

I would like to create some logic which should always run before Save is done. I work with the SelfServiced model. I tried the manual, forum search, but couldn't find the solution. Which doesn't mean it's not in the manual of on the forum, but I couldn't find it.

Stuff I would like to do is: Stamp at every update, upon creation, validate some rules (overlapping planning items, etc.)

Any suggestions?

Greets, Gab****

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 03-Mar-2005 18:43:19   

Use 2 class scenario, override InsertEntity and UpdateEntity. In there, first perform your logic, then call base.InsertEntity/UpdateEntity. You can also use IEntityValidator objects to validate objects, which is called before a save takes place.

Frans Bouma | Lead developer LLBLGen Pro
jspanocsi
User
Posts: 145
Joined: 04-Mar-2005
# Posted on: 22-Mar-2005 21:34:08   

Otis wrote:

Use 2 class scenario, override InsertEntity and UpdateEntity. In there, first perform your logic, then call base.InsertEntity/UpdateEntity. You can also use IEntityValidator objects to validate objects, which is called before a save takes place.

I tried doing this by overriding INsertEntity and UpdateEntity and now I get a concurrency exception whenever I try to insert or save a record. Any ideas?

Here is what I did for update.

Protected Overloads Overrides Function UpdateEntity() As Boolean Me.ModifyUserId = someuserid Me.ModifyDateTime = DateTime.Now MyBase.UpdateEntity() End Function

insert is basically the same

Thanks!

jspanocsi
User
Posts: 145
Joined: 04-Mar-2005
# Posted on: 22-Mar-2005 21:50:12   

OOPS nevermind stupid mistake. Forgot to return the value of the mybase calls.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 22-Mar-2005 22:14:15   

jspanocsi wrote:

OOPS nevermind stupid mistake. Forgot to return the value of the mybase calls.

Heh, indeed! I looked at your previous posting but didn't notice this mistake and flagged it for later reply, but indeed you have to return the value you get back, because based on that value, the code decides if there are rows affected or not. If the value is 0, it throws a concurrencyexception if the save was recursive. simple_smile

Frans Bouma | Lead developer LLBLGen Pro