I use the IPostUpdateEventListener interface to now update the audit log, capture old and new values, and then save each updated field in the Audit table and all that jive. The works swell, but there are two last requirements that I have difficulty filling out:
- Show on which employee the update was.
- Display the "friendly" name of the updated field.
For # 1, my first instinct was to use reflection, and look for and capture the “Employee” property on this object to find out which employee it was for, but it quickly falls apart when you are in several objects on the chart without automatic a way to return to this Employee object.
Ideas for solution # 1 ranged from the requirement for the Parent property on each object, so I can cross the graph looking for the Employee type (which, for me, would pollute our domain too much for a simple concern) is a separate SQL job for converting foriegn keys and filling in the Employee identifier after the fact (I would prefer not to support a separate SQL task, since everything that is actually the code based at this stage), and this SQL operation will be rather unpleasant very fast).
As for the second requirement, I can get the actual property name, which has changed just fine. For the good 80% - 90% of our fields, the property name (properly formatted) is what we show, so I can just specify a name based on the Pascal case. The remaining fields, however, do not coincide for various reasons. We use ASP.NET MVC and Fluent HTML constructors from MvcContrib, but even if we change the setting to such an extent that we have an attribute in the view model that reevaluates what should be the name of the field (and therefore have it in the code instead just a view), there is no real way to map these attributes from view models to persisted domain objects.
The final pragmatic solution to both problems would be to call the audit service for logging after each update operation in another service, passing in the field names and employee information as needed, but, well, I really don't want to go there for obvious reasons .
Ideas for any problem would be very helpful. Finding and breaking my brain for a couple of days didn’t bring anything useful - most people seem to stop at a simple recording of old or new records or just a “created / updated” time stamp on the record itself.
Darrell mozingo
source share