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) { 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); } }