What would I do ... create a couple of classes. There is an audit trail that collects a bunch of audit trails. Each audit record is either Edit or Delete , and contains the record that has been changed and the old value of the object, if applicable.
Well, since several types of objects will be involved (Customer, Product, ...), which tells me that these types should be common.
This brings me to:
public class AuditLog<T> { public int UserID { get; set; } public string LastSaved { get; set;} [XmlArrayItem("Entry")] public List<AuditRecord<T>> Records; } public enum Flavor { Edit, Delete } public class AuditRecord<T> { public AuditRecord() { Stamp = DateTime.Now; } [XmlAttribute("action")] public Flavor Action { get; set;} [XmlAttribute("stamp")] public DateTime Stamp { get; set;} public T Before; public T After;
And then for a class like this
public class Customer { public string Name { get; set; } public string City { get; set; } public String Country { get; set; } }
... you would get a document like this:
<AuditLogOfCustomer> <UserID>0</UserID> <LastSaved>2012 Jun 16 20:42:53</LastSaved> <Records> <Entry action="Edit" stamp="2012-06-16T20:42:52.9622344-07:00"> <Before> <Name>Sheldon</Name> <City>Ipswich</City> <Country>UK</Country> </Before> <After> <Name>Sheldon</Name> <City>London</City> <Country>UK</Country> </After> </Entry> <Entry action="Delete" stamp="2012-06-16T20:42:52.9642345-07:00"> <Before> <Name>Sheldon</Name> <City>London</City> <Country>UK</Country> </Before> </Entry> </Records> </AuditLogOfCustomer>
code: http://pastebin.com/PKiEefnX
source share