public AuditLog CreateLogRecord(ISystemUser user) { Type entityType = DbEntry.Entity.GetType().GetEntityType(); if (!EntityTrackingConfiguration.IsTrackingEnabled(entityType)) { return(null); } DateTime changeTime = DateTime.UtcNow; var newlog = new AuditLog { UserId = user.UserId, ClinicId = user.ClinicId, EventDateUTC = changeTime, EventType = _eventType, TypeId = EntityTrackingConfiguration.GetTypeId(entityType), RecordId = RecordId }; var logDetails = _changeLogDetailsAuditor.GetLogDetails(); logDetails.ForEach(x => x.Log = newlog); newlog.LogDetails = logDetails; if (newlog.LogDetails.Any()) { return(newlog); } else { return(null); } }
public void BeforeSaveChanges() { _logBuilders = _dbContext.ChangeTracker .Entries() .Where(p => (p.State == EntityState.Deleted || p.State == EntityState.Modified || p.State == EntityState.Added) && EntityTrackingConfiguration.IsTrackingEnabled(p.Entity.GetType().GetEntityType()) ) .Select(x => new LogBuilder(x, _dbContext)) .ToList(); _logBuilders.ForEach(x => x.BeforeSaveChanges()); }
internal AuditLog CreateLogRecord(object userName, EventType eventType, ITrackerContext context, ExpandoObject metadata) { Type entityType = _dbEntry.Entity.GetType().GetEntityType(); if (!EntityTrackingConfiguration.IsTrackingEnabled(entityType)) { return(null); } DateTime changeTime = DateTime.UtcNow; //todo: make this a static class DbMapping mapping = new DbMapping(context, entityType); List <PropertyConfiguerationKey> keyNames = mapping.PrimaryKeys().ToList(); AuditLog newlog = new AuditLog { UserName = userName?.ToString(), EventDateUTC = changeTime, EventType = eventType, TypeFullName = entityType.FullName, RecordId = GetPrimaryKeyValuesOf(_dbEntry, keyNames).ToString() }; List <LogMetadata> logMetadata = metadata .Where(x => x.Value != null) .Select(m => new LogMetadata { AuditLog = newlog, Key = m.Key, Value = m.Value?.ToString() }) .ToList(); newlog.Metadata = logMetadata; ChangeLogDetailsAuditor detailsAuditor = GetDetailsAuditor(eventType, newlog); newlog.LogDetails = detailsAuditor.CreateLogDetails().ToList(); if (newlog.LogDetails.Any()) { return(newlog); } else { return(null); } }
internal AuditLog CreateLogRecord(object userName, EventType eventType, ITrackerContext context, ExpandoObject metadata) { Type entityType = _dbEntry.Entity.GetType(); if (!EntityTrackingConfiguration.IsTrackingEnabled(entityType)) { return(null); } DateTime changeTime = DateTime.UtcNow; //changed to static class by Aaron Sulwer 3/16/2018 List <PropertyConfigurationKey> keyNames = (context as DbContext).GetKeyNames(entityType).ToList(); var newlog = new AuditLog { UserName = userName?.ToString(), EventDateUTC = changeTime, EventType = eventType, TypeFullName = entityType.FullName, RecordId = GetPrimaryKeyValuesOf(_dbEntry, keyNames).ToString() }; var logMetadata = metadata .Where(x => x.Value != null) .Select(m => new LogMetadata { AuditLog = newlog, Key = m.Key, Value = m.Value?.ToString() }) .ToList(); newlog.Metadata = logMetadata; var detailsAuditor = GetDetailsAuditor(eventType, newlog); newlog.LogDetails = detailsAuditor.CreateLogDetails().ToList(); if (newlog.LogDetails.Any()) { return(newlog); } else { return(null); } }
internal AuditLog CreateLogRecord(object userName, EventType eventType, ITrackerContext context) { Type entityType = _dbEntry.Entity.GetType().GetEntityType(); if (!EntityTrackingConfiguration.IsTrackingEnabled(entityType)) { return(null); } DateTime changeTime = DateTime.UtcNow; //todo: make this a static class var mapping = new DbMapping(context, entityType); List <PropertyConfiguerationKey> keyNames = mapping.PrimaryKeys().ToList(); var newlog = new AuditLog { UserName = userName?.ToString(), EventDateUTC = changeTime, EventType = eventType, TypeFullName = entityType.FullName, RecordId = GetPrimaryKeyValuesOf(_dbEntry, keyNames).ToString() }; var detailsAuditor = GetDetailsAuditor(eventType, newlog); newlog.LogDetails = detailsAuditor.CreateLogDetails().ToList(); if (newlog.LogDetails.Any()) { return(newlog); } else { return(null); } }