Skip to content

Instantly share code, notes, and snippets.

@rodrimaia
Created April 21, 2014 08:39
Show Gist options
  • Save rodrimaia/11136419 to your computer and use it in GitHub Desktop.
Save rodrimaia/11136419 to your computer and use it in GitHub Desktop.
Save changes with IAuditable
public override int SaveChanges()
{
// var auditUser = HttpContext.Current.User.Identity.Name;
DateTime auditDate = DateTime.UtcNow;
foreach (DbEntityEntry<IAuditable> entry in ChangeTracker.Entries<IAuditable>())
{
if (entry.State == EntityState.Added)
{
entry.Entity.CreatedOn = auditDate;
entry.Entity.ModifiedOn = auditDate;
// entry.Entity.CreatedBy = auditUser;
// entry.Entity.ModifiedBy = auditUser;
}
else if (entry.State == EntityState.Modified)
{
entry.Entity.ModifiedOn = auditDate;
// entry.Entity.ModifiedBy = auditUser;
}
}
return base.SaveChanges();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment