public override void OnException(ExceptionContext context)
        {
            var error = new
            {
                Success = false,
                Errors  = new[] { context.Exception.Message }
            };

            context.Result = new ObjectResult(error)
            {
                StatusCode = 500
            };

            var           StatusCode = context.HttpContext.Response.StatusCode;
            LogErrorModel errorLog   = new LogErrorModel
            {
                StatusCode       = StatusCode,
                RequestId        = context.HttpContext.Response.Headers["requestId"],
                ExceptionMessage = context.Exception.Message,
                StackTrace       = context.Exception.StackTrace,
                TimeOfError      = DateTime.Now
            };
            var service = (BudgetService)context.HttpContext.RequestServices.GetService(typeof(BudgetService));

            service.CreateErrorLog(errorLog);
            //context.Result = new JsonResult(errorLog);
            context.ExceptionHandled = true;
        }
        public string LogError(LogErrorModel logErrorModel)
        {
            string success;

            try
            {
                using (var mdb = new OggleBoobleMySqContext())
                {
                    mdb.ErrorLogs.Add(new ErrorLog()
                    {
                        PkId         = Guid.NewGuid().ToString(),
                        ActivityCode = logErrorModel.ActivityCode,
                        ErrorMessage = logErrorModel.ErrorMessage,
                        CalledFrom   = logErrorModel.CalledFrom,
                        Severity     = logErrorModel.Severity,
                        VisitorId    = logErrorModel.VisitorId,
                        Occured      = DateTime.Now
                    });
                    mdb.SaveChanges();
                    success = "ok";
                }
            }
            catch (Exception ex)
            {
                success = Helpers.ErrorDetails(ex);
            }
            return(success);
        }
        ///////////////////////



        public List <ComponenteModel> GetComponentesRol(int aRol)
        {
            List <ComponenteModel> ComponenteModellist = new List <ComponenteModel>();

            try
            {
                using (var connection = Util.ConnectionFactory.conexion())
                {
                    connection.Open();

                    SqlCommand command = connection.CreateCommand();

                    command.Parameters.AddWithValue("@IdRol", aRol);

                    command.CommandType = CommandType.StoredProcedure;

                    command.CommandText = "PermisosUsuarioSelectByIdRol";

                    SqlDataReader reader = command.ExecuteReader();

                    while (reader.Read())
                    {
                        ComponenteModel oRow = new ComponenteModel();
                        oRow.Id          = (int)(reader["Id"]);
                        oRow.Nombre      = reader["Nombre"] == DBNull.Value ? null : (string)reader["Nombre"];
                        oRow.Codigo      = reader["Codigo"] == DBNull.Value ? null : (string)reader["Codigo"];
                        oRow.Descripcion = reader["Descripcion"] == DBNull.Value ? null : (string)reader["Descripcion"];
                        oRow.Estado      = reader["Estado"] == DBNull.Value ? false : Convert.ToInt16(reader["Estado"]) == 1 ? true : false;
                        oRow.IdPadre     = reader["IdPadre"] == DBNull.Value ? null : (int?)Convert.ToInt32(reader["IdPadre"]);
                        //oRow.Usuario_creador = reader["USUARIO_CREADOR"] == DBNull.Value ? null : (string)reader["USUARIO_CREADOR"];
                        //oRow.Usuario_modificador = reader["USUARIO_MODIFICADOR"] == DBNull.Value ? null : (string)reader["USUARIO_MODIFICADOR"];
                        //oRow.Fecha_creacion = (DateTime)reader["FECHA_CREACION"];
                        //oRow.Fecha_modificacion = reader["FECHA_MODIFICACION"] == DBNull.Value ? null : reader["FECHA_MODIFICACION"] as DateTime?;
                        ComponenteModellist.Add(oRow);
                    }
                }

                return(ComponenteModellist);
            }
            catch (SqlException ex)
            {
                daLogError daerror = new daLogError();
                var        e       = new LogErrorModel("", "No se pudo obtener componentes ",
                                                       TipoOperacion.Select, "Capa datos", ex, ex.Number);
                daerror.InsertarError(e);
            }
            catch (Exception ex)
            {
                daLogError daerror = new daLogError();
                var        e       = new LogErrorModel("", "No se pudo obtener componentes ",
                                                       TipoOperacion.Select, "Capa datos", ex);
                daerror.InsertarError(e);
            }
            return(null);
        }
        public bool InsertByRol(int idComponente, int idRol)
        {
            try
            {
                using (var connection = Util.ConnectionFactory.conexion())
                {
                    connection.Open();

                    SqlTransaction sqlTran = connection.BeginTransaction();

                    SqlCommand command = connection.CreateCommand();

                    command.Transaction = sqlTran;

                    command.Parameters.AddWithValue("@idComponente", idComponente);
                    command.Parameters.AddWithValue("@idRol", idRol);

                    command.CommandType = CommandType.StoredProcedure;
                    command.CommandText = "sp_tComponente";

                    int afectados = command.ExecuteNonQuery();
                    int identity  = Convert.ToInt32(command.Parameters["@IDENTITY"].Value.ToString());

                    // Commit the transaction.
                    sqlTran.Commit();

                    connection.Close();
                    connection.Dispose();

                    if (afectados > 0)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            catch (SqlException ex)
            {
                daLogError daerror = new daLogError();
                var        e       = new LogErrorModel("", "No se pudo insertar componente ",
                                                       TipoOperacion.Insert, "Capa datos", ex, ex.Number);
                daerror.InsertarError(e);
            }
            catch (Exception ex)
            {
                daLogError daerror = new daLogError();
                var        e       = new LogErrorModel("", "No se pudo insertar componentes ",
                                                       TipoOperacion.Insert, "Capa datos", ex);
                daerror.InsertarError(e);
            }
            return(false);
        }
        public bool CambiarPorUsuario(PermisosUsuarioModel oRow, ref string error)
        {
            try
            {
                using (var connection = Util.ConnectionFactory.conexion())
                {
                    connection.Open();

                    SqlCommand command = connection.CreateCommand();
                    command.Parameters.Clear();
                    command.Parameters.AddWithValue("@Id_componente", oRow.Id_componente);
                    command.Parameters.AddWithValue("@Id_usuario", oRow.Id_usuario);
                    command.Parameters.AddWithValue("@Estado", oRow.Estado);
                    command.Parameters.AddWithValue("@USUARIO_CREADOR", oRow.USUARIO_CREADOR);

                    command.CommandType = CommandType.StoredProcedure;
                    command.CommandText = "PermisosAlterarByIdUsuario";

                    int afectados = command.ExecuteNonQuery();
                    connection.Close();
                    connection.Dispose();
                    if (afectados > 0)
                    {
                        return(true);
                    }
                    else
                    {
                        daLogError daerror = new daLogError();
                        var        e       = new LogErrorModel(oRow.USUARIO_CREADOR, "Error al Habilitar Permiso", TipoOperacion.Insert, "datos");
                        daerror.InsertarError(e);
                        error = e.MensajeUsuario;
                        return(false);
                    }
                }
            }
            catch (SqlException ex)
            {
                daLogError daerror = new daLogError();
                var        e       = new LogErrorModel(oRow.USUARIO_CREADOR, "Error al Habilitar Permiso",
                                                       TipoOperacion.Insert, "Capa datos", ex, ex.Number, 1);
                daerror.InsertarError(e);
                error = e.MensajeUsuario;
                return(false);
            }
            catch (Exception ex)
            {
                daLogError daerror = new daLogError();
                var        e       = new LogErrorModel(oRow.USUARIO_CREADOR, "Error al Habilitar Permiso",
                                                       TipoOperacion.Insert, "Capa datos", ex, null, 1);
                daerror.InsertarError(e);
                error = e.MensajeUsuario;
                return(false);
            }
        }
示例#6
0
        public IActionResult SaveLogError([FromBody] LogErrorModel model)
        {
            string DbConn = _iconfiguration.GetSection("MySettings").GetSection("DbConn").Value;
            var    msg    = new Message <LogErrorModel>();
            var    data   = DbClientFactory <ErrorDbClient> .Instance.SaveLogs(model, DbConn);

            if (data == "C200")
            {
                msg.IsSuccess     = true;
                msg.ReturnMessage = "LogError saved successfully";
            }
            return(Ok(msg));
        }
        public List <ComponenteModel> ObtenerTodosComponentes()
        {
            List <ComponenteModel> ComponenteModellist = new List <ComponenteModel>();

            try
            {
                using (var connection = Util.ConnectionFactory.conexion())
                {
                    connection.Open();

                    SqlCommand command = connection.CreateCommand();

                    command.CommandType = CommandType.StoredProcedure;

                    command.Parameters.Clear();
                    command.CommandText = "ComponentesSelectAll";

                    SqlDataReader reader = command.ExecuteReader();

                    while (reader.Read())
                    {
                        ComponenteModel oRow = new ComponenteModel();
                        oRow.Id          = Convert.ToInt32((reader["Id"]));
                        oRow.Nombre      = (reader["Nombre"] == DBNull.Value ? null : reader["Nombre"].ToString());
                        oRow.Descripcion = (reader["Descripcion"] == DBNull.Value ? null : reader["Descripcion"].ToString());
                        oRow.Codigo      = (reader["Codigo"] == DBNull.Value ? null : reader["Codigo"].ToString());
                        oRow.IdPadre     = (reader["IdPadre"] == DBNull.Value ? null : (int?)Convert.ToInt32(reader["IdPadre"]));
                        oRow.Estado      = (reader["Estado"] == DBNull.Value ? false : Convert.ToInt16(reader["Estado"]) == 1 ? true : false);
                        ComponenteModellist.Add(oRow);
                    }
                }

                return(ComponenteModellist);
            }
            catch (SqlException ex)
            {
                daLogError daerror = new daLogError();
                var        e       = new LogErrorModel("", "No se pudo obtener componentes ",
                                                       TipoOperacion.Select, "Capa datos", ex, ex.Number);
                daerror.InsertarError(e);
            }
            catch (Exception ex)
            {
                daLogError daerror = new daLogError();
                var        e       = new LogErrorModel("", "No se pudo obtener componentes ",
                                                       TipoOperacion.Select, "Capa datos", ex);
                daerror.InsertarError(e);
            }
            return(null);
        }
示例#8
0
        public static LogErrorModel TranslateAsUser(this SqlDataReader reader, bool isList = false)
        {
            if (!isList)
            {
                if (!reader.HasRows)
                {
                    return(null);
                }
                reader.Read();
            }
            var item = new LogErrorModel();

            if (reader.IsColumnExists("appName"))
            {
                item.appName = SqlHelper.GetNullableString(reader, "appName");
            }

            if (reader.IsColumnExists("toEmail"))
            {
                item.toEmail = SqlHelper.GetNullableString(reader, "toEmail");
            }

            if (reader.IsColumnExists("error"))
            {
                item.error = SqlHelper.GetNullableString(reader, "error");
            }

            if (reader.IsColumnExists("date"))
            {
                item.date = SqlHelper.GetNullableString(reader, "date");
            }

            if (reader.IsColumnExists("sendEmail"))
            {
                item.sendEmail = SqlHelper.GetBoolean(reader, "sendEmail");
            }

            if (reader.IsColumnExists("className"))
            {
                item.className = SqlHelper.GetNullableString(reader, "className");
            }

            if (reader.IsColumnExists("methodName"))
            {
                item.methodName = SqlHelper.GetNullableString(reader, "methodName");
            }

            return(item);
        }
示例#9
0
        /// <summary>
        /// Saves a record to the RolUsuarioModel table.
        /// returns True if value saved successfully else false
        /// Throw exception with message value EXISTS if the data is duplicate
        /// </summary>
        public bool Insert(RolUsuarioModel aRolUsuarioModel)
        {
            try
            {
                using (var connection = Util.ConnectionFactory.conexion())
                {
                    connection.Open();

                    SqlCommand command = connection.CreateCommand();

                    command.Parameters.AddWithValue("@Id_Persona_", aRolUsuarioModel.Id_persona);
                    command.Parameters.AddWithValue("@Id_rol_", aRolUsuarioModel.Id_rol);
                    command.Parameters.AddWithValue("@USUARIO_CREADOR_", aRolUsuarioModel.Usuario_creador);
                    command.CommandType = CommandType.StoredProcedure;
                    command.CommandText = "RolUsuarioInsertBYUsuario";

                    int afectados = command.ExecuteNonQuery();

                    connection.Close();
                    connection.Dispose();

                    if (afectados > 0)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            catch (SqlException ex)
            {
                daLogError daerror = new daLogError();
                var        e       = new LogErrorModel("", "Error el deshabilitar rol",
                                                       TipoOperacion.Insert, "Capa datos", ex, ex.Number);
                daerror.InsertarError(e);
            }
            catch (Exception ex)
            {
                daLogError daerror = new daLogError();
                var        e       = new LogErrorModel("", "Error el deshabilitar rol ",
                                                       TipoOperacion.Insert, "Capa datos", ex);
                daerror.InsertarError(e);
            }
            return(false);
        }
示例#10
0
        public void InsertarError(LogErrorModel pError)
        {
            try
            {
                using (var connection = Util.ConnectionFactory.conexion())
                {
                    connection.Open();

                    SqlCommand command = connection.CreateCommand();
                    command.Parameters.Clear();
                    command.Parameters.AddWithValue("@Usuario", pError.Usuario);
                    command.Parameters.AddWithValue("@MensajeUsuario", pError.MensajeUsuario);
                    string operation = pError.operacion.ToString();
                    command.Parameters.AddWithValue("@TipoOperacion", operation);
                    if (pError.NumeroSQl != null)
                    {
                        command.Parameters.AddWithValue("@NumeroSQl", pError.NumeroSQl);
                    }
                    if (pError.nivelGravedad != null)
                    {
                        command.Parameters.AddWithValue("@nivelGravedad", pError.nivelGravedad);
                    }
                    if (pError.Message != null)
                    {
                        command.Parameters.AddWithValue("@Mensaje", pError.Message.ToString());
                    }
                    if (pError.StackTrace != null)
                    {
                        command.Parameters.AddWithValue("@StackTrace", pError.StackTrace.ToString());
                    }
                    command.Parameters.AddWithValue("@IpEquipo", pError.IpEquipo.ToString());
                    command.Parameters.AddWithValue("@HostName", pError.HostName.ToString());
                    command.Parameters.AddWithValue("@CapaProyecto", pError.CapaProyecto.ToString());
                    command.CommandType = CommandType.StoredProcedure;
                    command.CommandText = "RegistrarError";
                    command.ExecuteNonQuery();
                    connection.Close();
                    connection.Dispose();
                }
            }
            catch (Exception ex)
            {
                return;
            }
        }
        public bool VerificarPermisoPorUsuario(int idComponente, int idUser)
        {
            try
            {
                using (var connection = Util.ConnectionFactory.conexion())
                {
                    connection.Open();

                    SqlCommand command = connection.CreateCommand();

                    command.Parameters.AddWithValue("@idComponente", idComponente);
                    command.Parameters.AddWithValue("@idUsuario", idUser);

                    command.CommandType = CommandType.StoredProcedure;

                    command.CommandText = "VerificarPermisoPorUsuario";

                    SqlDataReader reader = command.ExecuteReader();

                    if (reader.Read())
                    {
                        return(true);
                    }
                }
                return(false);
            }
            catch (SqlException ex)
            {
                daLogError daerror = new daLogError();
                var        e       = new LogErrorModel("", "no se pudo verificar el permiso con id usuario: " + idUser.ToString(),
                                                       TipoOperacion.Select, "Capa datos", ex, ex.Number);
                daerror.InsertarError(e);
            }
            catch (Exception ex)
            {
                daLogError daerror = new daLogError();
                var        e       = new LogErrorModel("", "no se pudo verificarel permiso con id usuario: " + idUser.ToString(),
                                                       TipoOperacion.Select, "Capa datos", ex);
                daerror.InsertarError(e);
            }
            return(false);
        }
示例#12
0
        public string SaveLogs(LogErrorModel model, string connString)
        {
            var outParam = new SqlParameter("@ReturnCode", SqlDbType.NVarChar, 20)
            {
                Direction = ParameterDirection.Output
            };

            SqlParameter[] param =
            {
                new SqlParameter("@appName",    model.appName),
                new SqlParameter("@toEmail",    model.toEmail),
                new SqlParameter("@error",      model.error),
                new SqlParameter("@date",       model.date),
                new SqlParameter("@sendEmail",  model.sendEmail),
                new SqlParameter("@className",  model.className),
                new SqlParameter("@methodName", model.methodName),
                outParam
            };
            SqlHelper.ExecuteProcedureReturnString(connString, "SaveLogError", param);
            return((string)outParam.Value);
        }
        public void DeleteByUsuario(PermisosUsuarioModel oRow, ref string error)
        {
            try
            {
                using (var connection = Util.ConnectionFactory.conexion())
                {
                    connection.Open();

                    SqlCommand command = connection.CreateCommand();
                    command.Parameters.Clear();
                    command.Parameters.AddWithValue("@idUsuario", oRow.Id_usuario);

                    command.CommandType = CommandType.StoredProcedure;
                    command.CommandText = "PermisosDeleteByIdUsuario";

                    command.ExecuteNonQuery();
                    connection.Close();
                    connection.Dispose();
                }
            }
            catch (SqlException ex)
            {
                daLogError daerror = new daLogError();
                var        e       = new LogErrorModel(oRow.USUARIO_CREADOR, "Error al Deshabilitar Permiso",
                                                       TipoOperacion.Delete, "Capa datos", ex, ex.Number, 1);
                daerror.InsertarError(e);
                error = e.MensajeUsuario;
                return;
            }
            catch (Exception ex)
            {
                daLogError daerror = new daLogError();
                var        e       = new LogErrorModel(oRow.USUARIO_CREADOR, "Error al Deshabilitar Permiso",
                                                       TipoOperacion.Delete, "Capa datos", ex, null, 1);
                daerror.InsertarError(e);
                error = e.MensajeUsuario;
            }
        }
示例#14
0
        public string LogError(LogErrorModel logErrorModel)
        {
            string success;

            try
            {
                using (var db = new OggleBoobleMySqlContext())
                {
                    db.ErrorLogs.Add(new ErrorLog()
                    {
                        VisitorId    = logErrorModel.VisitorId,
                        ErrorCode    = logErrorModel.ErrorCode,
                        ErrorMessage = logErrorModel.ErrorMessage,
                        CalledFrom   = logErrorModel.CalledFrom,
                        FolderId     = logErrorModel.FolderId,
                        Occured      = DateTime.Now
                    });
                    db.SaveChanges();
                    success = "ok";
                }
            }
            catch (Exception ex) { success = Helpers.ErrorDetails(ex); }
            return(success);
        }
示例#15
0
        void validarVersiones()
        {
            Thread.Sleep(5000);
            try
            {
                string VersionServer     = ObtenerRowVersionSesionActiva();
                bool   accesoAComponente = true;
                bool   UsuarioActivo     = true;
                bool   conexionPerdida   = true;
                while (VersionServer == Session.Version && accesoAComponente && UsuarioActivo && conexionPerdida)
                {
                    Thread.Sleep(3000);
                    VersionServer = ObtenerRowVersionSesionActiva();
                    try
                    {
                        if (NombreComponentActivo != null)
                        {
                            accesoAComponente = AccesoComponenteByNombre(NombreComponentActivo);
                        }

                        using (WsSistemaBancario.PersonaServiceClient per = new WsSistemaBancario.PersonaServiceClient())
                        {
                            int idUser = Convert.ToInt32(Session.UserCodigo);
                            UsuarioActivo = per.Persona_ObtenerUno(idUser).Activo;
                        }
                    }
                    catch (Exception)
                    {
                        conexionPerdida = false;
                    }
                }
                if (VersionServer == null)
                {
                    errorLogin = "******";
                }
                else if (VersionServer != Session.Version)
                {
                    errorLogin = "******";
                }
                else if (!accesoAComponente)
                {
                    errorLogin = "******";
                    CerrarSesion();
                }
                else if (!UsuarioActivo)
                {
                    errorLogin = "******";

                    CerrarSesion();
                }
                else if (!conexionPerdida)
                {
                    errorLogin = "******";
                    CerrarSesion();
                }
                else
                {
                    errorLogin = "******";
                    CerrarSesion();
                }
                try
                {
                    using (wsRegistroError.LogErrorClient err = new wsRegistroError.LogErrorClient())
                    {
                        LogErrorModel log = new LogErrorModel(Session.UserNombreCompleto, errorLogin, TipoOperacion.otro, "capa UI", "Error en el inicio de sesión");
                        err.LogError_RegistrarError(log);
                    }
                }
                catch (Exception ex)
                {
                }
                noCerrarSesion = true;

                this.Close();
            }
            catch (Exception ex)
            {
                // ThreadConexion.Abort();
            }
        }
        /// <summary>
        /// Updates a record to the ComponenteModel table.
        /// returns True if value saved successfully else false
        /// Throw exception with message value EXISTS if the data is duplicate
        /// </summary>
        public bool Update(ComponenteModel aComponenteModel, ref string error)
        {
            try
            {
                using (var connection = Util.ConnectionFactory.conexion())
                {
                    connection.Open();

                    SqlCommand command = connection.CreateCommand();

                    command.Parameters.AddWithValue("@Id", aComponenteModel.Id);
                    command.Parameters.AddWithValue("@Descripcion", aComponenteModel.Descripcion);
                    if (aComponenteModel.Estado)
                    {
                        command.Parameters.AddWithValue("@Estado", 1);
                    }
                    else
                    {
                        command.Parameters.AddWithValue("@Estado", 0);
                    }
                    command.Parameters.AddWithValue("@USUARIO_MODIFICADOR", aComponenteModel.Usuario_Modificador);
                    command.Parameters.AddWithValue("@FECHA_MODIFICACION", aComponenteModel.Fecha_Modificacion);
                    command.CommandType = CommandType.StoredProcedure;
                    command.CommandText = "ComponenteUpdate";

                    int afectados = command.ExecuteNonQuery();

                    connection.Close();
                    connection.Dispose();

                    if (afectados > 0)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            catch (SqlException ex)
            {
                if (ex.Number == 2627)
                {
                    daLogError daerror = new daLogError();

                    var e = new LogErrorModel("", "Error al Actualizar el permiso con Id: " + aComponenteModel.Codigo,
                                              TipoOperacion.Update, "Capa datos", ex, ex.Number);
                    daerror.InsertarError(e);
                    error = "Ya existe la descripcion de rol.";
                }
                else
                {
                    daLogError daerror = new daLogError();

                    var e = new LogErrorModel("", "Error al Actualizar el permiso con Id: " + aComponenteModel.Codigo,
                                              TipoOperacion.Update, "Capa datos", ex, ex.Number);
                    daerror.InsertarError(e);
                    error = "Error al actualizar rol.";
                }
            }
            catch (Exception ex)
            {
                daLogError daerror = new daLogError();
                var        e       = new LogErrorModel("", "Error al Eliminar el permiso con Id: " + aComponenteModel.Codigo,
                                                       TipoOperacion.Update, "Capa datos", ex);
                daerror.InsertarError(e);
                error = "Error al actualizar rol.";
            }
            return(false);
        }
示例#17
0
 void ILogError.LogError_RegistrarError(LogErrorModel _logError)
 {
     logError.RegistrarError(_logError);
 }
        /// <summary>
        /// Saves a record to the ComponenteModel table.
        /// returns True if value saved successfully else false
        /// Throw exception with message value EXISTS if the data is duplicate
        /// </summary>
        public bool Insert(ComponenteModel aComponenteModel, int id_user)
        {
            try
            {
                using (var connection = Util.ConnectionFactory.conexion())
                {
                    connection.Open();

                    SqlTransaction sqlTran = connection.BeginTransaction();

                    SqlCommand command = connection.CreateCommand();

                    command.Transaction = sqlTran;

                    command.Parameters.AddWithValue("@pMode", 4);
                    command.Parameters.AddWithValue("@ID_user", id_user);
                    command.Parameters.AddWithValue("@Nombre", aComponenteModel.Nombre);
                    command.Parameters.AddWithValue("@Descripcion", aComponenteModel.Descripcion);
                    command.Parameters.AddWithValue("@Id_aplicacion", aComponenteModel.Id_aplicacion == null ? (object)DBNull.Value : aComponenteModel.Id_aplicacion);
                    command.Parameters.AddWithValue("@Estado", aComponenteModel.Estado);
                    command.Parameters.AddWithValue("@Codigo", aComponenteModel.Codigo);
                    command.Parameters.AddWithValue("@IdPadre", aComponenteModel.IdPadre == null ? (object)DBNull.Value : aComponenteModel.IdPadre);

                    SqlParameter paramId = new SqlParameter("@IDENTITY", SqlDbType.Int);
                    paramId.Direction = ParameterDirection.Output;
                    command.Parameters.Add(paramId);

                    command.CommandType = CommandType.StoredProcedure;
                    command.CommandText = "sp_tComponente";

                    int afectados = command.ExecuteNonQuery();
                    int identity  = Convert.ToInt32(command.Parameters["@IDENTITY"].Value.ToString());

                    // Commit the transaction.
                    sqlTran.Commit();

                    connection.Close();
                    connection.Dispose();

                    if (afectados > 0)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            catch (SqlException ex)
            {
                daLogError daerror = new daLogError();
                var        e       = new LogErrorModel("", "No se pudo insertar componente ",
                                                       TipoOperacion.Insert, "Capa datos", ex, ex.Number);
                daerror.InsertarError(e);
            }
            catch (Exception ex)
            {
                daLogError daerror = new daLogError();
                var        e       = new LogErrorModel("", "No se pudo insertar componentes ",
                                                       TipoOperacion.Insert, "Capa datos", ex);
                daerror.InsertarError(e);
            }
            return(false);
        }
        /// <summary>
        /// Selects all the objects of ComponenteModel table.
        /// </summary>
        public List <ComponenteModel> ComponenteModelSelectAll()
        {
            List <ComponenteModel> ComponenteModellist = new List <ComponenteModel>();

            try
            {
                using (var connection = Util.ConnectionFactory.conexion())
                {
                    connection.Open();

                    SqlCommand command = connection.CreateCommand();

                    command.Parameters.AddWithValue("@pMode", 1);
                    command.CommandType = CommandType.StoredProcedure;

                    command.CommandText = "sp_tComponente";

                    SqlDataReader reader = command.ExecuteReader();

                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            int    Id            = (int)(reader["Id"]);
                            string Nombre        = (string)(reader["Nombre"]);
                            string Descripcion   = (string)(reader["Descripcion"]);
                            int?   Id_aplicacion = reader["Id_aplicacion"] as int?;
                            bool   Estado        = (bool)(reader["Estado"]);
                            string Codigo        = (string)(reader["Codigo"]);
                            int?   IdPadre       = reader["IdPadre"] as int?;

                            ComponenteModellist.Add(new ComponenteModel
                            {
                                Id            = Id,
                                Nombre        = Nombre,
                                Descripcion   = Descripcion,
                                Id_aplicacion = Id_aplicacion,
                                Estado        = Estado,
                                Codigo        = Codigo,
                                IdPadre       = IdPadre,
                            });
                        }
                    }
                }

                return(ComponenteModellist);
            }
            catch (SqlException ex)
            {
                daLogError daerror = new daLogError();
                var        e       = new LogErrorModel("", "No se pudo obtener componentes ",
                                                       TipoOperacion.Select, "Capa datos", ex, ex.Number);
                daerror.InsertarError(e);
            }
            catch (Exception ex)
            {
                daLogError daerror = new daLogError();
                var        e       = new LogErrorModel("", "No se pudo obtener componentes ",
                                                       TipoOperacion.Select, "Capa datos", ex);
                daerror.InsertarError(e);
            }
            return(null);
        }
        /// <summary>
        /// Selects the Single object of ComponenteModel table.
        /// </summary>
        public ComponenteModel GetComponenteModel(int aId)
        {
            ComponenteModel ComponenteModel = null;

            try
            {
                using (var connection = Util.ConnectionFactory.conexion())
                {
                    connection.Open();

                    SqlCommand command = connection.CreateCommand();

                    command.Parameters.AddWithValue("@IdComponente", aId);


                    command.CommandType = CommandType.StoredProcedure;

                    command.CommandText = "ComponentesSelectId";

                    SqlDataReader reader = command.ExecuteReader();

                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            int      Id                  = (int)(reader["Id"]);
                            string   Nombre              = (string)(reader["Nombre"]);
                            string   Descripcion         = (string)(reader["Descripcion"]);
                            int?     Id_aplicacion       = reader["Id_aplicacion"] == DBNull.Value ? null : reader["Id_aplicacion"] as int?;
                            bool     Estado              = (bool)(reader["Estado"]);
                            string   Codigo              = (string)(reader["Codigo"]);
                            int?     IdPadre             = reader["IdPadre"] == DBNull.Value ? null : reader["IdPadre"] as int?;
                            string   Usuario_Creador     = (string)reader["USUARIO_CREADOR"];
                            string   Usuario_Modificador = reader["USUARIO_MODIFICADOR"] == DBNull.Value ? null : (string)reader["USUARIO_MODIFICADOR"];
                            DateTime?Fecha_Creacion      = reader["FECHA_CREACION"] as DateTime?;
                            DateTime?Fecha_Modificacion  = reader["Fecha_Modificacion"] == DBNull.Value ? null : reader["FECHA_MODIFICACION"] as DateTime?;

                            ComponenteModel = new ComponenteModel
                            {
                                Id            = Id,
                                Nombre        = Nombre,
                                Descripcion   = Descripcion,
                                Id_aplicacion = Id_aplicacion,
                                Estado        = Estado,
                                Codigo        = Codigo,
                                IdPadre       = IdPadre,

                                Usuario_Creador     = Usuario_Creador,
                                Usuario_Modificador = Usuario_Modificador,
                                Fecha_Creacion      = (DateTime)Fecha_Creacion,
                                Fecha_Modificacion  = Fecha_Modificacion
                            };
                        }
                    }
                }

                return(ComponenteModel);
            }
            catch (SqlException ex)
            {
                daLogError daerror = new daLogError();
                var        e       = new LogErrorModel("", "No se pudo obtener componente ",
                                                       TipoOperacion.Insert, "Capa datos", ex, ex.Number);
                daerror.InsertarError(e);
            }
            catch (Exception ex)
            {
                daLogError daerror = new daLogError();
                var        e       = new LogErrorModel("", "No se pudo obtener componente ",
                                                       TipoOperacion.Insert, "Capa datos", ex);
                daerror.InsertarError(e);
            }
            return(null);
        }
示例#21
0
 public void CreateErrorLog(LogErrorModel log)
 {
     _log.LogError($"errorLog:{JsonConvert.SerializeObject(log)}");
 }
示例#22
0
        /// <summary>
        /// Updates a record to the RolesModel table.
        /// returns True if value saved successfully else false
        /// Throw exception with message value EXISTS if the data is duplicate
        /// </summary>
        public bool Update(RolesModel aRolesModel, ref string Error)
        {
            try
            {
                using (var connection = Util.ConnectionFactory.conexion())
                {
                    connection.Open();

                    SqlTransaction sqlTran = connection.BeginTransaction();

                    SqlCommand command = connection.CreateCommand();

                    command.Transaction = sqlTran;

                    //command.Parameters.AddWithValue("@ID_user", ID_user);
                    command.Parameters.AddWithValue("@USUARIO_MODIFICADOR", aRolesModel.Usuario_modificador == null ? (object)DBNull.Value : aRolesModel.Usuario_modificador);

                    command.Parameters.AddWithValue("@Id", aRolesModel.Id);
                    command.Parameters.AddWithValue("@Descripcion", aRolesModel.Descripcion);
                    command.Parameters.AddWithValue("@Estado", aRolesModel.Estado);

                    command.CommandType = CommandType.StoredProcedure;
                    command.CommandText = "RolesUpdate";

                    int afectados = command.ExecuteNonQuery();

                    // Commit the transaction.
                    sqlTran.Commit();

                    connection.Close();
                    connection.Dispose();

                    if (afectados > 0)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            catch (SqlException ex)
            {
                daLogError daerror = new daLogError();
                if (ex.Number == 2627)
                {
                    var e = new LogErrorModel(aRolesModel.Usuario_modificador, "Rol existente",
                                              TipoOperacion.Update, "Capa datos", ex, ex.Number);
                    daerror.InsertarError(e);
                    Error = e.MensajeUsuario;
                }
                else
                {
                    var e = new LogErrorModel(aRolesModel.Usuario_modificador, "Error al Actualizar Rol, digite Nuevamente.",
                                              TipoOperacion.Update, "Capa datos", ex, ex.Number);
                    daerror.InsertarError(e);
                    Error = e.MensajeUsuario;
                }
            }
            catch (Exception ex)
            {
                daLogError daerror = new daLogError();
                var        e       = new LogErrorModel(aRolesModel.Usuario_modificador, "Error interno en actualizar rol",
                                                       TipoOperacion.Update, "Capa datos", ex);
                daerror.InsertarError(e);
                Error = e.MensajeUsuario;
            }
            return(false);
        }