Exemplo n.º 1
0
 public static void AuditDataValue(object sender, IEnumerable <T1> data, IFreeSql orm, TableInfo table)
 {
     if (data?.Any() != true)
     {
         return;
     }
     if (orm.Aop.AuditValue == null)
     {
         return;
     }
     foreach (var d in data)
     {
         if (d == null)
         {
             continue;
         }
         foreach (var col in table.Columns.Values)
         {
             object val       = col.GetMapValue(d);
             var    auditArgs = new Aop.AuditValueEventArgs(Aop.AuditValueType.Update, col, table.Properties[col.CsName], val);
             orm.Aop.AuditValue(sender, auditArgs);
             if (auditArgs.IsChanged)
             {
                 col.SetMapValue(d, val = auditArgs.Value);
             }
         }
     }
 }
Exemplo n.º 2
0
 public static void AuditDataValue(object sender, T1 data, IFreeSql orm, TableInfo table, Dictionary <string, bool> changedDict)
 {
     if (orm.Aop.AuditValue == null)
     {
         return;
     }
     if (data == null)
     {
         return;
     }
     foreach (var col in table.Columns.Values)
     {
         object val       = col.GetMapValue(data);
         var    auditArgs = new Aop.AuditValueEventArgs(Aop.AuditValueType.Update, col, table.Properties[col.CsName], val);
         orm.Aop.AuditValue(sender, auditArgs);
         if (auditArgs.IsChanged)
         {
             col.SetMapValue(data, val = auditArgs.Value);
             if (changedDict != null && changedDict.ContainsKey(col.Attribute.Name) == false)
             {
                 changedDict.Add(col.Attribute.Name, true);
             }
         }
     }
 }
Exemplo n.º 3
0
 public static void AuditDataValue(object sender, T1 data, IFreeSql orm, TableInfo table, Dictionary <string, bool> changedDict)
 {
     if (orm.Aop.AuditValueHandler == null)
     {
         return;
     }
     if (data == null)
     {
         return;
     }
     if (typeof(T1) == typeof(object) && new[] { table.Type, table.TypeLazy }.Contains(data.GetType()) == false)
     {
         throw new Exception($"操作的数据类型({data.GetType().DisplayCsharp()}) 与 AsType({table.Type.DisplayCsharp()}) 不一致,请检查。");
     }
     foreach (var col in table.Columns.Values)
     {
         object val       = col.GetValue(data);
         var    auditArgs = new Aop.AuditValueEventArgs(Aop.AuditValueType.Update, col, table.Properties[col.CsName], val);
         orm.Aop.AuditValueHandler(sender, auditArgs);
         if (auditArgs.ValueIsChanged)
         {
             col.SetValue(data, val = auditArgs.Value);
             if (changedDict != null && changedDict.ContainsKey(col.Attribute.Name) == false)
             {
                 changedDict.Add(col.Attribute.Name, true);
             }
         }
         if (val == null && col.Attribute.MapType == typeof(string) && col.Attribute.IsNullable == false)
         {
             col.SetValue(data, val = "");
         }
     }
 }
 public static void AuditDataValue(object sender, IEnumerable <T1> data, IFreeSql orm, TableInfo table, Dictionary <string, bool> changedDict)
 {
     if (data?.Any() != true)
     {
         return;
     }
     if (orm.Aop.AuditValueHandler == null)
     {
         return;
     }
     foreach (var d in data)
     {
         if (d == null)
         {
             continue;
         }
         foreach (var col in table.Columns.Values)
         {
             object val       = col.GetValue(d);
             var    auditArgs = new Aop.AuditValueEventArgs(Aop.AuditValueType.InsertOrUpdate, col, table.Properties[col.CsName], val);
             orm.Aop.AuditValueHandler(sender, auditArgs);
             if (auditArgs.IsChanged)
             {
                 col.SetValue(d, val = auditArgs.Value);
                 if (changedDict != null && changedDict.ContainsKey(col.Attribute.Name) == false)
                 {
                     changedDict.Add(col.Attribute.Name, true);
                 }
             }
         }
     }
 }
Exemplo n.º 5
0
 public static void AuditDataValue(object sender, T1 data, IFreeSql orm, TableInfo table, Dictionary <string, bool> changedDict)
 {
     if (data == null)
     {
         return;
     }
     foreach (var col in table.Columns.Values)
     {
         object val = col.GetMapValue(data);
         if (col.Attribute.IsPrimary && col.Attribute.MapType.NullableTypeOrThis() == typeof(Guid) && (val == null || (Guid)val == Guid.Empty))
         {
             col.SetMapValue(data, val = FreeUtil.NewMongodbId());
         }
         if (orm.Aop.AuditValue != null)
         {
             var auditArgs = new Aop.AuditValueEventArgs(Aop.AuditValueType.Insert, col, table.Properties[col.CsName], val);
             orm.Aop.AuditValue(sender, auditArgs);
             if (auditArgs.IsChanged)
             {
                 col.SetMapValue(data, val = auditArgs.Value);
                 if (changedDict != null && changedDict.ContainsKey(col.Attribute.Name) == false)
                 {
                     changedDict.Add(col.Attribute.Name, true);
                 }
             }
         }
     }
 }
Exemplo n.º 6
0
 public static void AuditDataValue(object sender, T1 data, IFreeSql orm, TableInfo table, Dictionary <string, bool> changedDict)
 {
     if (data == null)
     {
         return;
     }
     if (typeof(T1) == typeof(object) && new[] { table.Type, table.TypeLazy }.Contains(data.GetType()) == false)
     {
         throw new Exception($"操作的数据类型({data.GetType().DisplayCsharp()}) 与 AsType({table.Type.DisplayCsharp()}) 不一致,请检查。");
     }
     foreach (var col in table.Columns.Values)
     {
         object val = col.GetValue(data);
         if (orm.Aop.AuditValueHandler != null)
         {
             var auditArgs = new Aop.AuditValueEventArgs(Aop.AuditValueType.Insert, col, table.Properties[col.CsName], val);
             orm.Aop.AuditValueHandler(sender, auditArgs);
             if (auditArgs.ValueIsChanged)
             {
                 col.SetValue(data, val = auditArgs.Value);
                 if (changedDict != null && changedDict.ContainsKey(col.Attribute.Name) == false)
                 {
                     changedDict.Add(col.Attribute.Name, true);
                 }
             }
         }
         if (col.Attribute.IsPrimary)
         {
             val = col.GetDbValue(data);
             if (col.Attribute.MapType.NullableTypeOrThis() == typeof(Guid) && (val == null || (Guid)val == Guid.Empty))
             {
                 col.SetValue(data, val = FreeUtil.NewMongodbId());
             }
             else if (col.CsType.NullableTypeOrThis() == typeof(Guid))
             {
                 val = col.GetValue(data);
                 if (val == null || (Guid)val == Guid.Empty)
                 {
                     col.SetValue(data, val = FreeUtil.NewMongodbId());
                 }
             }
         }
         if (val == null && col.Attribute.MapType == typeof(string) && col.Attribute.IsNullable == false)
         {
             col.SetValue(data, val = "");
         }
         if (val == null && col.Attribute.MapType == typeof(byte[]) && col.Attribute.IsVersion)
         {
             col.SetValue(data, val = Utils.GuidToBytes(Guid.NewGuid()));
         }
     }
 }