Return true or false on insert success

Posts   
 
    
shekar
User
Posts: 327
Joined: 26-Mar-2010
# Posted on: 21-Jun-2013 16:48:08   

LLBLGEN 4.0 Self Servicing LLBLGEN Runtime framework

Hi Team

As part of my business logic in uow, I need to return true or false on insert update and delete. I mean return true if action is success else return false.

How can I do this

DvK
User
Posts: 318
Joined: 22-Mar-2006
# Posted on: 21-Jun-2013 17:23:22   

If a persisted new entity contains a filled PK then it's succesful, not ? Both the SaveEntity and DeleteEntity method return a Boolean type.

shekar
User
Posts: 327
Joined: 26-Mar-2010
# Posted on: 21-Jun-2013 17:42:00   

DvK wrote:

If a persisted new entity contains a filled PK then it's succesful, not ? Both the SaveEntity and DeleteEntity method return a Boolean type.

Can you help me with syntax using UOW. By the way am not deleting entity physically am just updating a Flag in DB as deleted

Example code


 Public Shared Function Save(description As String) As Boolean
        Try
            Dim uow = New UnitOfWork()
            Dim title = New TitleEntity
            title.Description = ChangeCaseClass.Titlecase(ConvertNullDbNullClass.IsNull(description))
            title.Createddate = DateTimeClass.Currentdatetime()
            title.Createduserid = ConstantClass.Userid
            title.Modifieddate = DateTimeClass.Currentdatetime()
            title.Flag = ConstantClass.Validflag
            uow.AddForSave(title)
uow.Commit(New Transaction(IsolationLevel.ReadCommitted, "UOW"), True)
[b]So what do I write here ?[/b]
        Catch ex As Exception
            ErrorHandlerClass.LogMessage(ex.Message + ex.StackTrace)
            Throw
        End Try
    End Function

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 22-Jun-2013 08:01:32   

You could use UOW Callbacks. For example add a Insert/Update callback.

However, For what you are doing, I think the best option is to save entities separately. You can use a transaction to make sure that all your actions are atomic.

Public Shared Function Save(description As String) As Boolean
        Try
            Dim tx= New Transaction(IsolationLevel.ReadCommitted, "MyTx")
            Dim title = New TitleEntity
            title.Description = ChangeCaseClass.Titlecase(ConvertNullDbNullClass.IsNull(description))
            title.Createddate = DateTimeClass.Currentdatetime()
            title.Createduserid = ConstantClass.Userid
            title.Modifieddate = DateTimeClass.Currentdatetime()
            title.Flag = ConstantClass.Validflag
            
             tx.Add(title);
             Dim success = title.Save()
             tx.Commit();
    
             If (sucess)
                        // your code here
             EndIf

        Catch ex As Exception
            ErrorHandlerClass.LogMessage(ex.Message + ex.StackTrace)
            Throw
        End Try
    End Function
David Elizondo | LLBLGen Support Team
shekar
User
Posts: 327
Joined: 26-Mar-2010
# Posted on: 22-Jun-2013 08:23:47   

daelmo wrote:

You could use UOW Callbacks. For example add a Insert/Update callback.

However, For what you are doing, I think the best option is to save entities separately. You can use a transaction to make sure that all your actions are atomic.

Public Shared Function Save(description As String) As Boolean
        Try
            Dim tx= New Transaction(IsolationLevel.ReadCommitted, "MyTx")
            Dim title = New TitleEntity
            title.Description = ChangeCaseClass.Titlecase(ConvertNullDbNullClass.IsNull(description))
            title.Createddate = DateTimeClass.Currentdatetime()
            title.Createduserid = ConstantClass.Userid
            title.Modifieddate = DateTimeClass.Currentdatetime()
            title.Flag = ConstantClass.Validflag
            
             tx.Add(title);
             Dim success = title.Save()
             tx.Commit();
    
             If (sucess)
                        // your code here
             EndIf

        Catch ex As Exception
            ErrorHandlerClass.LogMessage(ex.Message + ex.StackTrace)
            Throw
        End Try
    End Function

Thank you