12.3. Solution

Now the system has a way for the user to set up auditing, but it has to be implemented in the business layer. Luckily, the only classes that can be audited in the Paid Time Off solution are the EditObject classes, and there is a base class that can handle the majority of the logic needed to audit the object without having to completely overhaul the existing objects. Some custom code is needed in each object but it is minimal.

The first thing to consider is where the audit data will be stored. The requirements state that the system must store the user, date/time, before value, after value, and type of action that occurred, such as add, update, or delete. All of this data will be stored in one table called ENTAudit. The table structure is shown in Figure 12-3. The field names are straightforward.

Figure 12.3. Figure 12-3

The Chapter12Auditing.sql script contains the DDL to create this table and the stored procedures associated with it. The standard five stored procedures can be created for this table without any customization. Once the table is created, add the table and the stored procedures to the DataContext object as you've done before using the ORM Designer. Again, remember to add the partial class to the CustomizedEntities.cs file for this table. Also add the ENTAuditData class to the Framework folder in the DAL project.

Now you can add the business classes: ...

Get ASP.NET 3.5 Enterprise Application Development with Visual Studio® 2008: Problem - Design - Solution now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.