Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Data.Entity.Infrastructure;
- using UIWeb.Infrastructure.Logging;
- using UIWeb.Infrastructure.Security;
- using UIWeb.Models;
- namespace UIWeb.Data.Interceptors
- {
- public class AuditChangeInterceptor : ChangeInterceptor<IAmAuditable>
- {
- public ILogger Logger { get; set; }
- private readonly IPrincipalProvider principalProvider;
- public AuditChangeInterceptor(IPrincipalProvider principalProvider)
- {
- this.principalProvider = principalProvider;
- }
- protected override void OnBeforeInsert(DbEntityEntry entry, IAmAuditable item, InterceptionContext context)
- {
- Logger.Trace("OnBeforeInsert");
- item.Created = item.Updated = DateTime.UtcNow;
- item.CreatedBy = item.UpdatedBy = principalProvider.GetCurrent().Identity.Name;
- base.OnBeforeInsert(entry, item, context);
- }
- protected override void OnBeforeUpdate(DbEntityEntry entry, IAmAuditable item, InterceptionContext context)
- {
- Logger.Trace("OnBeforeInsert");
- item.Updated = DateTime.UtcNow;
- item.UpdatedBy = principalProvider.GetCurrent().Identity.Name;
- base.OnBeforeUpdate(entry, item, context);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement