Created
April 21, 2014 08:39
-
-
Save rodrimaia/11136419 to your computer and use it in GitHub Desktop.
Save changes with IAuditable
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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