Example #1
0
        public AuditMetaDataEntity ToAuditMetaDataEntity()
        {
            AuditMetaDataEntity auditMetaData = new AuditMetaDataEntity();

            auditMetaData.DisplayName        = DisplayName;
            auditMetaData.Schema             = SchemaName;
            auditMetaData.Table              = TableName;
            auditMetaData.SchemaTable        = $"{(!string.IsNullOrEmpty(SchemaName) ? SchemaName + "." : "")}{TableName}";
            auditMetaData.ReadablePrimaryKey = ReadablePrimaryKey;
            auditMetaData.HashPrimaryKey     = HashReferenceId;

            return(auditMetaData);
        }
Example #2
0
        public AuditEntity ToAuditEntity(AuditMetaDataEntity auditMetaData)
        {
            AuditEntity audit = new AuditEntity();

            audit.OldValues      = OldValues.Count == 0 ? null : JsonConvert.SerializeObject(OldValues);
            audit.NewValues      = NewValues.Count == 0 ? null : JsonConvert.SerializeObject(NewValues);
            audit.EntityState    = EntityState;
            audit.DateTimeOffset = DateTimeOffset.UtcNow;
            audit.ByUser         = ByUser;
            audit.AuditMetaData  = auditMetaData;

            return(audit);
        }
 private void BeginTrackingAuditEntries(IEnumerable <AuditEntry> auditEntries)
 {
     foreach (var auditEntry in auditEntries)
     {
         auditEntry.Update();
         AuditMetaDataEntity auditMetaDataEntity        = auditEntry.ToAuditMetaDataEntity();
         AuditMetaDataEntity existedAuditMetaDataEntity = AuditMetaDatas.FirstOrDefault(x => x.HashPrimaryKey == auditMetaDataEntity.HashPrimaryKey && x.SchemaTable == auditMetaDataEntity.SchemaTable);
         if (existedAuditMetaDataEntity == default)
         {
             Add(auditEntry.ToAuditEntity(auditMetaDataEntity));
         }
         else
         {
             Add(auditEntry.ToAuditEntity(existedAuditMetaDataEntity));
         }
     }
 }