Otis wrote:
The only option you have is throw an exception. The reason is that it has to cancel the transaction currently active, which can be deeply nested so an exception is the only safe remedy.
Maybe you can help me solve this.
Here is what we do when we save and validate data.
ASP.NET Page
- Load data to the controls from the business object
- User Edits Data
- User Submits Page - Saves Page
- On save routine we set the values from the page to the business object
- During the save of the business object any violation causes the object not to be saved to the database using a transactionscope object which is hidden in my custom business scope object.. Anytime there is not a complete called it obviously does not work.
- These violations are added to a collection of violations that are then used to report the errors to the user of the asp.net. This is done because we don’t want to continue to right user friendly violation errors in all of the gui front end forms or pages. Each business object which is very reusable has its violations written in a user friendly way. Basically added to a collection that is then formatted and displayed to the user if present.
- We display the errors using a common control that is on every page. We don’t have to write this code again ever. We just add violations in our business objects, if there are any. We also tie these into our user controls so we can show a red box around controls that have violated a rule. I wont go into that.
- If there are no errors, then a success is called on the screen to confirm to the user they did the right thing.
This is all done through a BusinessScope(Our internal singleton object that wraps the business object actions) that is only alive for the time of the business object transaction.
Here is an example of how we wrap the business objects code on the save of a page. I am in the middle of transferring our business objects to LLBL, but I need to be able to cancel the save without raising an exception. Exceptions are expensive anyway, but so are transaction scopes.
Anyway, I love the idea of LLBL, but I have not been able to figure out a way to get the below functionality.
Using lBusinessScope As GEN.Sys.BusinessScope.BusinessScope = New GEN.Sys.BusinessScope.BusinessScope(New Web.BusinessScope.RoundTripRequest(DirectCast(Me.Page, CRMPage)))
Me.mObjContentCallSchedule = New BAC.BL.CallSchedule
If MyBase.EditObjectID > 0 Then Me.mObjContentCallSchedule.FillByID(MyBase.EditObjectID)
Me.mObjContentCallSchedule.NameBind(Me.txtTitle)
Me.mObjContentCallSchedule.DescriptionBind(Me.txtDescription)
Me.mObjContentCallSchedule.MonthofYear = CType(Me.ddlMonth.SelectedValue, EnumMonthsOfYearFull)
Me.mObjContentCallSchedule.Year = Me.ddlYear.SelectedValue
Me.mObjContentCallSchedule.DisplayOrderBind(Me.txtDisplayOrder)
Me.mObjContentCallSchedule.ObjectStatus = CType(Me.ddlStatus.SelectedValue, EnumObjectStatus)
Me.mObjContentCallSchedule.Save()
lBusinessScope.Complete()
If Not GEN.Sys.BusinessScope.CurrentBusinessScope.HasViolations Then
MyBase.EditObjectID = Me.mObjContentCallSchedule.ObjectID
End If
End Using
If this works a control we have on the master page, just displays a success in a standard section on the screen.
If there is a violation then the violations are displayed and the entire transaction is not commited.
Anyway, the only way for me to fit this in LLBL is to cancel the save, when I see violations, otherwise I do what, wrap every business object in a try catch, on the catch then do the test?
Bryan