I have a web api, I generate all models with Entity Framework with a database-first approach.
Then what I do is I create all controllers with actions using Entity Framework , what I want is to find a way to audit all changes by all crud actions (create, read, update, delete) done in those controllers. This way of auditing those changes should be done automatically for me, what I mean by this is that if I add a new controller created with entity framework with all actions, it should have the auditing thing.
For example, if someone does a get of /api/Example/4
, what I want is now, to have a tuple in my database telling the id of the user that did the action, the type of operation (in this case a get), etc..
This is my Audit class created with EF:
[Table("Audit")]
public partial class Audit
{
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public decimal AuditId { get; set; }
public DateTime AuditDate { get; set; }
[Required]
[StringLength(100)]
public string AuditTableName { get; set; }
[Required]
public string AuditDescription { get; set; }
[Required]
[StringLength(400)]
public string AuditShortDescription { get; set; }
[Required]
[StringLength(3)]
public string AuditAction { get; set; }
public short UserId { get; set; }
public virtual Usuario Usuario { get; set; }
}