diff --git a/src/api/framework/Core/Domain/AuditableEntity.cs b/src/api/framework/Core/Domain/AuditableEntity.cs index 6639a0215..c0738d232 100644 --- a/src/api/framework/Core/Domain/AuditableEntity.cs +++ b/src/api/framework/Core/Domain/AuditableEntity.cs @@ -4,9 +4,13 @@ namespace FSH.Framework.Core.Domain; public class AuditableEntity : BaseEntity, IAuditable, ISoftDeletable { + [IgnoreAuditTrail] public DateTimeOffset Created { get; set; } + [IgnoreAuditTrail] public Guid CreatedBy { get; set; } + [IgnoreAuditTrail] public DateTimeOffset LastModified { get; set; } + [IgnoreAuditTrail] public Guid? LastModifiedBy { get; set; } public DateTimeOffset? Deleted { get; set; } public Guid? DeletedBy { get; set; } diff --git a/src/api/framework/Core/Domain/Contracts/IgnoreAuditTrailAttribute.cs b/src/api/framework/Core/Domain/Contracts/IgnoreAuditTrailAttribute.cs new file mode 100644 index 000000000..d9d16e150 --- /dev/null +++ b/src/api/framework/Core/Domain/Contracts/IgnoreAuditTrailAttribute.cs @@ -0,0 +1,7 @@ +namespace FSH.Framework.Core.Domain.Contracts; + +[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property)] +public class IgnoreAuditTrailAttribute : Attribute +{ +} + diff --git a/src/api/framework/Infrastructure/Persistence/Interceptors/AuditInterceptor.cs b/src/api/framework/Infrastructure/Persistence/Interceptors/AuditInterceptor.cs index 6c2d819ca..4adcb0187 100644 --- a/src/api/framework/Infrastructure/Persistence/Interceptors/AuditInterceptor.cs +++ b/src/api/framework/Infrastructure/Persistence/Interceptors/AuditInterceptor.cs @@ -36,7 +36,7 @@ private async Task PublishAuditTrailsAsync(DbContextEventData eventData) eventData.Context.ChangeTracker.DetectChanges(); var trails = new List(); var utcNow = timeProvider.GetUtcNow(); - foreach (var entry in eventData.Context.ChangeTracker.Entries().Where(x => x.State is EntityState.Added or EntityState.Deleted or EntityState.Modified).ToList()) + foreach (var entry in eventData.Context.ChangeTracker.Entries().Where(x => x.State is EntityState.Added or EntityState.Deleted or EntityState.Modified && x.Entity.GetType().GetCustomAttributes(typeof(IgnoreAuditTrailAttribute), false).Length == 0).ToList()) { var userId = currentUser.GetUserId(); var trail = new TrailDto() @@ -47,7 +47,7 @@ private async Task PublishAuditTrailsAsync(DbContextEventData eventData) DateTime = utcNow }; - foreach (var property in entry.Properties) + foreach (var property in entry.Properties.Where(p => p.Metadata.PropertyInfo?.GetCustomAttributes(typeof(IgnoreAuditTrailAttribute), false).Length == 0)) { if (property.IsTemporary) {