Using transaction and show broken rules


Author
Message
StrataFrame Team
S
StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
Yes, that is the correct way to do it.  The only thing I would change is if you're planning on threading this or running this on a web application (any time you might have this code running more than once at the same time), you'll want to specify a transaction key for the Begin, Commit, Rollback, and saves.  Maybe something like Guid.NewGuid().ToString() to make it random (but save it off so you can pass the same value to all of the method calls that are part of the same transaction).  But yeah, what you have looks good. 

After each of the Save() calls, the BrokenRules property on the business object will have all of the broken rules.  You can enumerate through that collection and create a flat list of the broken rules for display to the user.

Chan
Chan
Advanced StrataFrame User (725 reputation)Advanced StrataFrame User (725 reputation)Advanced StrataFrame User (725 reputation)Advanced StrataFrame User (725 reputation)Advanced StrataFrame User (725 reputation)Advanced StrataFrame User (725 reputation)Advanced StrataFrame User (725 reputation)Advanced StrataFrame User (725 reputation)Advanced StrataFrame User (725 reputation)
Group: Forum Members
Posts: 533, Visits: 2K
Hi,

I have code to update some tables (not visible on screen) upon Form.AfterSave() event fired using transaction as shown below.

1. Is it the "right way"?

2. I want show broken rules if failed. How should I show them? Any advice?

public SaveUndoResult SaveToTransfer()
{
  SaveUndoResult loReturn = SaveUndoResult.Success;
  try
  {
    //PushDataToTransfer();
    BusinessLayer.TransactionBegin("", IsolationLevel.ReadCommitted);
    if (loReturn == SaveUndoResult.Success)
    {
       loReturn = _TransfersBO.Save(true);
    }
    if (loReturn == SaveUndoResult.Success)
    {
       _TransferDetailsBO.Save(true);
    }
    if (loReturn == SaveUndoResult.Success)
    {
      _PInvoiceTransferBO.Save(true);
    }
  }
  catch (DataLayerSavingException ex)
  {
    throw ex;
  }
  catch (Exception ex)
  {
    throw new BusinessLayerException("An error occurred while saving the data to the server.", ex);
  }
  finally
  {
    if (loReturn == SaveUndoResult.Success)
    {
      BusinessLayer.TransactionCommit("");
    }
    else
    {
    BusinessLayer.TransactionRollback("");
    }
  }
  return loReturn;

}


GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search