Ejemplo n.º 1
0
        public void insert(Object obj, UAuditoria data, string esquema, string tabla)
        {
            UAuditoria eAuditoria = new UAuditoria();

            eAuditoria.Fecha   = DateTime.Now;
            eAuditoria.Accion  = "INSERT";
            eAuditoria.User_bd = "SQL";
            eAuditoria.Schema  = esquema;
            eAuditoria.Session = data.Session;
            eAuditoria.Tabla   = tabla;
            eAuditoria.Pk      = data.Pk.ToString();

            //JObject jObject = new JObject();

            //foreach (PropertyInfo propertyInfo in obj.GetType().GetProperties())
            //{
            //    if (propertyInfo.PropertyType == typeof(string) || propertyInfo.PropertyType == typeof(int) || propertyInfo.PropertyType == typeof(Boolean))
            //    {
            //        jObject[propertyInfo.Name] = propertyInfo.GetValue(obj).ToString();
            //    }
            //}

            eAuditoria.Data = JsonConvert.SerializeObject(obj);
            DAuditoria.add(eAuditoria);
        }
Ejemplo n.º 2
0
 public static void add(UAuditoria eAuditoria)
 {
     using (var dbc = new Mapeo("auditoria"))
     {
         dbc.Entry(eAuditoria).State = EntityState.Added;
         dbc.SaveChanges();
     }
 }
Ejemplo n.º 3
0
        public void update(Object newObj, Object oldObj, UAuditoria data, string esquema, string tabla)
        {
            UAuditoria eAuditoria = new UAuditoria();

            eAuditoria.Fecha   = DateTime.Now;
            eAuditoria.Accion  = "UPDATE";
            eAuditoria.User_bd = "SQL";
            eAuditoria.Schema  = esquema;
            eAuditoria.Tabla   = tabla;
            eAuditoria.Pk      = data.Pk;
            eAuditoria.Session = data.Session;

            JObject jObject = new JObject();

            Boolean sinCambios = true;

            foreach (PropertyInfo propertyInfo in newObj.GetType().GetProperties())
            {
                if (propertyInfo.PropertyType == typeof(string) || propertyInfo.PropertyType == typeof(int) || propertyInfo.PropertyType == typeof(Boolean))
                {
                    if (propertyInfo.Name.Equals("Id"))
                    {
                        jObject[propertyInfo.Name] = propertyInfo.GetValue(newObj).ToString();
                    }
                    if (!propertyInfo.GetValue(newObj).ToString().Equals(propertyInfo.GetValue(oldObj).ToString()) && !propertyInfo.Name.Equals("pk"))
                    {
                        jObject["new_" + propertyInfo.Name] = propertyInfo.GetValue(newObj).ToString();
                        jObject["old_" + propertyInfo.Name] = propertyInfo.GetValue(oldObj).ToString();
                        sinCambios = false;
                    }
                }
                else if (propertyInfo.PropertyType == typeof(List <int>) && !JsonConvert.SerializeObject(propertyInfo.GetValue(newObj)).Equals(JsonConvert.SerializeObject(propertyInfo.GetValue(oldObj))))
                {
                    jObject["new_" + propertyInfo.Name] = JsonConvert.SerializeObject(propertyInfo.GetValue(newObj));
                    jObject["old_" + propertyInfo.Name] = JsonConvert.SerializeObject(propertyInfo.GetValue(oldObj));
                    sinCambios = false;
                }
            }

            if (sinCambios)
            {
                return;
            }

            eAuditoria.Data = JsonConvert.SerializeObject(jObject);
            DAuditoria.add(eAuditoria);
        }