Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Anyone implemented auditing?
Message
General information
Forum:
ASP.NET
Category:
The Mere Mortals .NET Framework
Miscellaneous
Thread ID:
01135910
Message ID:
01136596
Views:
14
Patrick,

>Yikes, a new requirement.
>
>Each table needs columns:
>LastUpdatedBy (both domain users and web users (username in db))
>LastUpdatedDate
>
>Anyone implemented something like this, gathering user info in a business object save override?

The best place to put this code is in the data access layer where you know exactly which rows were updated. Here's what you can do:

  1. Create a subclass of mmDataAccessSql (if you're using SQL server, otherwise use the appropriate data access class). We'll call it myDataAccessSql

  2. Override the CreateDataAdapter() method of myDataAccessSql, and add code that registers your custom handler method. In your custom event handler method, update the columns with the current date time. For example:
    public class myDataAccessSql : mmDataAccessSql
    {
    	/// <summary>
    	/// Data adapter factory method
    	/// </summary>
    	/// <returns></returns>
    	public override IDataAdapter CreateDataAdapter()
    	{
    		SqlDataAdapter DA = (SqlDataAdapter)base.CreateDataAdapter();
    		DA.RowUpdating += new SqlRowUpdatingEventHandler(this.RowUpdatingHandler);
    		return DA;
    	}
    
    
    	/// <summary>
    	/// Row updating handler
    	/// </summary>
    	/// <param name="sender">Event source</param>
    	/// <param name="e">Event args</param>
    	protected void RowUpdatingHandler(object sender, SqlRowUpdatingEventArgs e)
    	{
    		e.Row["LastUpdated"] = DateTime.Now;
    	}
    }
  3. Your last step is to instantiate your custom data access class rather than the mmDataAccessSql class. To do this, you can just override the Factory.cs method CreateDataAccessSql(). For example:
    public class Factory : mmFactoryDesktop
    {
    	public override OakLeaf.MM.Main.Data.mmDataAccessSql CreateDataAccessSql()
    	{
    		return new myDataAccessSql();
    	}
    }


Best Regards,
Kevin McNeish
Eight-Time .NET MVP
VFP and iOS Author, Speaker & Trainer
Oak Leaf Enterprises, Inc.
Chief Architect, MM Framework
http://www.oakleafsd.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform