|
Open the BaseClasses200x.vbproj (located in C:\Program Files\Iron Speed\Designer v5.x.x\BaseClasses\) in Visual Studio.
Open the BaseRecord.vb under ~\Data\. Insert the following code in OnInsertingRecord() and OnUpdatingRecord() methods.
Save and build the project. Copy the BaseClasses.dll to your existing projects’ BIN folder.
Visual Basic .NET:
Protected Overridable Sub OnInsertingRecord(ByVal e As System.ComponentModel.CancelEventArgs)
Dim dtColName As String = ConfigurationManager.AppSettings("InsertAuditDateColumn")
If Not String.IsNullOrEmpty(dtColName) Then
Dim dtCol As BaseColumn = TableAccess.TableDefinition.ColumnList.GetByInternalName
(dtColName)
If Not IsNothing(dtCol) Then
Parse(DateTime.Now, dtCol)
End If
End If
Dim userColName As String = ConfigurationManager.AppSettings("InsertAuditUserColumn")
If Not String.IsNullOrEmpty(userColName) Then
Dim userCol As BaseColumn = TableAccess.TableDefinition.ColumnList.GetByInternalName
(userColName)
If Not IsNothing(userCol) Then
Parse(DataAccessSettings.Current.SignedInUserId, userCol)
End If
End If
RaiseEvent InsertingRecord(Me, e)
End Sub
Protected Overridable Sub OnUpdatingRecord(ByVal e As System.ComponentModel.CancelEventArgs)
Dim dtColName As String = ConfigurationManager.AppSettings("UpdateAuditDateColumn")
If Not String.IsNullOrEmpty(dtColName) Then
Dim dtCol As BaseColumn = TableAccess.TableDefinition.ColumnList.GetByInternalName
(dtColName)
If Not IsNothing(dtCol) Then
Parse(DateTime.Now, dtCol)
End If
End If
Dim userColName As String = ConfigurationManager.AppSettings("UpdateAuditUserColumn")
If No String.IsNullOrEmpty(userColName) Then
Dim userCol As BaseColumn = TableAccess.TableDefinition.ColumnList.GetByInternalName
(userColName)
If Not IsNothing(userCol) Then
Parse(DataAccessSettings.Current.SignedInUserId, userCol)
End If
End If
RaiseEvent UpdatingRecord(Me, e)
End Sub
|
Next, insert the following key-value pairs in your project’s web.config.
<add key="InsertAuditDateColumn" value="CreatedOn"/>
<add key="InsertAuditUserColumn" value="CreatedBy"/>
<add key="UpdateAuditDateColumn" value="ChangedOn"/>
<add key="UpdateAuditUserColumn" value="ChangedBy"/>
|
Please note the code uses BaseRecord.TableAccess.TableDefinition to find the auditing fields, and
BaseRecord.Parse() method to modify them. This addresses Issue No. 1. For Issue No. 2, the code
checks whether an auditing field exists before modifying it. Since the auditing column names are
defined in web.config, they are easy to configure from project to project. If the columns are not
defined in web.config, the feature is effectively turned off. This addresses the concerns of Issue
No. 3.
|