Your question is incredibly broad, potentially too broad. From what I'm gathering though you have several tables, more than likely with different columns. Your looking for a generic approach, to simply write the proper content based on the column without too much code reproduction.
What you could and should do:
- Write out those tables.
- Determine the content that is required to be audited.
- Compare those tables too each other.
That often helps me determine to what degree content should be abstracted. This particular example may benefit from Inversion Of Control or Dependency Injection. This way you can inject particular audit's to particular Classes.
public interface IAudit<T>
{
void WriteToAudit(<T> model);
}
So this particular Interface will implement a Generic, which should represent your audit data model. Which can provide several differentiating models to better suite your requirements, while providing flexibility.
Now you would need to write your implementation classes, which inherit the interface.
public class Inventory : IAudit<InventoryModel>
{
public void WriteToAudit(InventoryModel model)
{
// Write your database content, then pass *Properties* from the model.
// Which will write for this particular table.
}
}
Now the powerful part of this approach:
public class Stuff
{
private IAudit audit;
public void DoSomething(model)
{
audit.WriteToAudit(model);
}
}
So now you could essentially create a new IAudit
, then you can pass is through several approaches:
This is an incredibly rough implementation and I may have several typos. This was a quick post, but hopefully this points you in the proper direction. More detail on the matter can be found here.