Пример #1
0
        public static int Patch <TTableInterface>(this Database db, DbPatchModel patch)
        {
            var binding = db.GetBinding(typeof(TTableInterface));

            var assemblies  = (string[])AppDomain.CurrentDomain.GetData("Assemblies");
            var permissions = Utility.GetInstanceWithInterface <IRequireDbPermission>(assemblies);

            var result = permissions.Any(x => !x.AllowPatch(patch));

            if (result)
            {
                return(0);
            }

            if (!String.IsNullOrEmpty(patch.Id))
            {
                var record = db.Table(patch.Table).FirstOrDefault(x => x.Id == patch.Id);
                SetValues(patch, record);

                return(1);
            }
            else
            {
                var records = db.Table(patch.Table).Where(patch.Where, patch.Params).ToList();
                records.ForEach(record => SetValues(patch, record));

                return(records.Count);
            }
        }
Пример #2
0
 private static void SetValues(DbPatchModel patch, DbRecord record)
 {
     patch.Values.Where(x => !patch.IgnoredColumns.Contains(x.Key))
     .ToList()
     .ForEach(x =>
     {
         try
         {
             record.SetValue(x.Key, x.Value);
         }
         catch (Exception ex)
         {
             Console.WriteLine($"Set value exception: {x.Key} {x.Value}");
             throw ex;
         }
     });
 }