Exemple #1
0
        public MODResultado CrearRastroAuditoria(MODRastroAuditoria rastro)
        {
            MODResultado resultado = new MODResultado();

            try
            {
                var coneccion = this.ObtenerConexionPrincipal();
                var a         = coneccion.Query("StpAuditoria", new
                {
                    accion = 3,
                    TipoAccionAuditoria = rastro.TipoAccionAuditoria,
                    ModeloDatos         = rastro.ModeloDatos,
                    FechaAccion         = rastro.FechaAccion,
                    CampoClaveID        = rastro.CampoClaveID,
                    ValorAntes          = rastro.ValorAntes,
                    ValorDespues        = rastro.ValorDespues,
                    Cambios             = rastro.Cambios,
                    Usuario             = rastro.Usuario,
                    Ip = rastro.Ip
                }, commandType: System.Data.CommandType.StoredProcedure).FirstOrDefault();
            }catch (Exception e)
            {
                resultado.Errores.Add(e.Message);
                Log.WriteLog(e, this.GetType().Namespace, Newtonsoft.Json.JsonConvert.SerializeObject(rastro), ErrorType.Error);
            }
            return(resultado);
        }
        public MODResultado CrearRastroAuditoria(EnumTipoAccionAuditoria Accion, string CampoClaveID, string modeloDatos, Object AnteriorObject, Object NuevoObject, string Usuario, string ip)
        {
            MODResultado resultado = new MODResultado();

            try
            {
                // get the differance
                CompareLogic compObjects = new CompareLogic();
                compObjects.Config.MaxDifferences = 99;
                compObjects.Config.TreatStringEmptyAndNullTheSame = true;
                compObjects.Config.MaxStructDepth = 5;
                ComparisonResult      compResult = compObjects.Compare(AnteriorObject, NuevoObject);
                List <DeltaAuditoria> DeltaList  = new List <DeltaAuditoria>();
                foreach (var change in compResult.Differences)
                {
                    DeltaAuditoria delta = new DeltaAuditoria();
                    if (change.PropertyName != "" && change.PropertyName.Substring(0, 1) == ".")
                    {
                        delta.NombreCampo = change.PropertyName.Substring(1, change.PropertyName.Length - 1);
                    }
                    else
                    {
                        delta.NombreCampo = change.PropertyName;
                    }
                    delta.ValorAntes   = change.Object1Value;
                    delta.ValorDespues = change.Object2Value;
                    DeltaList.Add(delta);
                }
                MODRastroAuditoria audit = new MODRastroAuditoria();
                audit.TipoAccionAuditoria = Accion;
                audit.ModeloDatos         = modeloDatos;
                audit.FechaAccion         = DateTime.Now;
                audit.CampoClaveID        = CampoClaveID;
                audit.ValorAntes          = JsonConvert.SerializeObject(AnteriorObject);
                audit.ValorDespues        = JsonConvert.SerializeObject(NuevoObject);
                audit.Cambios             = JsonConvert.SerializeObject(DeltaList);
                audit.Usuario             = Usuario;
                IAuditoriaDatos dal = FabricaDatos.CrearAuditoriaDatos;
                resultado = dal.CrearRastroAuditoria(audit);
            }
            catch (Exception e)
            {
                resultado.Errores.Add(e.Message);
                Log.WriteLog(e, this.GetType().Namespace, Newtonsoft.Json.JsonConvert.SerializeObject(new { Accion = Accion, CampoClaveID = CampoClaveID, modeloDatos = modeloDatos, AnteriorObject = AnteriorObject, NuevoObject = NuevoObject }), ErrorType.Error);
            }
            return(resultado);
        }