Public Class CerelogicBusinessObject Inherits ABusinessObject Public CurrentUser As String2) In the business object above, I utilize the HookPreSave method as follows:
Protected Overrides Function HookPreSave(ByVal table As DataTable) As Boolean Dim Result As Boolean = True Dim dr As DataRow For Each dr In table.Rows If dr.RowState = DataRowState.Modified Then dr("AuditLastAction") = "Modified" dr("AuditLastUser") = CurrentUser dr("AuditLastDateTime") = DateTime.UtcNow End If If dr.RowState = DataRowState.Added Then dr("AuditLastAction") = "Created" dr("AuditLastUser") = CurrentUser dr("AuditLastDateTime") = DateTime.UtcNow End If Next dr Return Result End Function 'HookPreSave3) Now in each web page UI where the user does editing to a record, I do something like this (in this case I'm using IntersoftPT's WebGrid 3.5 Enterprise to update a record):
Private Sub WebGrid1_UpdateRow(ByVal sender As Object, ByVal e As ISNet.WebUI.WebGrid.RowEventArgs) Handles WebGrid1.UpdateRow Dim ds As DataSet = CType(WebGrid1.DataSource, DataSet) ' update the changed row using proper dataadapter for each datatable. oMyBizObj.CurrentUser = CStr(Me.SecurityUserPk) Dim result As mmSaveDataResult = Me.oMyBizObj.SaveDataSet(ds) End SubA possible drawback to this approach is that the user id in your audit field is set to the PK value of the user logged in. You are not saving the actual user id or name. To get that, you would have to roll your own code to retrieve that from MM.NET's security tables. I believe Kevin plans to introduce some additional properties in MM.NET that will simplify this.