Exemplo n.º 1
0
        public static AdminLogTipo Get(EAdminLogTipo idLog)
        {
            int          id = (int)idLog;
            AdminLogTipo tipoLog;

            using (MySqlConnection connection = new MySqlConnection(DbAccess.Instance.ConnectionString))
            {
                MySqlCommand cmd = new MySqlCommand();
                cmd.Connection  = connection;
                cmd.CommandText = "SELECT * FROM admin_log_tipo WHERE admin_log_tipo_ID = @Id";
                cmd.CommandType = System.Data.CommandType.Text;

                cmd.Parameters.AddWithValue("@Id", id);

                connection.Open();

                using (MySqlDataReader reader = cmd.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        // Si ya está en el Diccionario, obtiene el objeto, de lo contrario, lo crea
                        if (!TiposLog.TryGetValue(id, out tipoLog))
                        {
                            tipoLog      = new AdminLogTipo();
                            TiposLog[id] = tipoLog;
                        }

                        // Actualiza los datos del tipo de log (sea nuevo o recien creado en memoria)
                        tipoLog.TipoLogId   = id;
                        tipoLog.Nombre      = reader["nombre"].ToString();
                        tipoLog.Descripción = reader["descripcion"].ToString();
                    }
                    else
                    {
                        return(null);
                    }
                }
            }

            return(tipoLog);
        }
Exemplo n.º 2
0
        public static AdminLog Get(int id)
        {
            AdminLog log = null;

            using (MySqlConnection connection = new MySqlConnection(DbAccess.Instance.ConnectionString))
            {
                MySqlCommand cmd = new MySqlCommand();
                cmd.Connection  = connection;
                cmd.CommandText = "SELECT * FROM admin_log WHERE admin_log_ID = @Id";
                cmd.CommandType = System.Data.CommandType.Text;

                cmd.Parameters.AddWithValue("@Id", id);

                connection.Open();

                using (MySqlDataReader reader = cmd.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        log       = new AdminLog(Admin.Get(reader["admin_nombre"].ToString()), AdminLogTipo.Get((EAdminLogTipo)Convert.ToInt32(reader["admin_log_tipo_ID"])));
                        log.LogId = id;
                        log.Fecha = Convert.ToDateTime(reader["fecha"]);
                    }
                    else
                    {
                        return(null);
                    }
                }
            }

            return(log);
        }
Exemplo n.º 3
0
        public static List <AdminLog> GetAll(string nombreAdmin)
        {
            List <AdminLog> logs = new List <AdminLog>();

            using (MySqlConnection connection = new MySqlConnection(DbAccess.Instance.ConnectionString))
            {
                MySqlCommand cmd = new MySqlCommand();
                cmd.Connection  = connection;
                cmd.CommandText = "SELECT * FROM admin_log WHERE admin_nombre = @NombreAdmin";
                cmd.CommandType = System.Data.CommandType.Text;

                cmd.Parameters.AddWithValue("@NombreAdmin", nombreAdmin);
                connection.Open();

                using (MySqlDataReader reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        int id = Convert.ToInt32(reader["admin_log_ID"]);

                        AdminLog log = new AdminLog(Admin.Get(reader["admin_nombre"].ToString()), AdminLogTipo.Get((EAdminLogTipo)Convert.ToInt32(reader["admin_log_tipo_ID"])));
                        log.LogId = id;
                        log.Fecha = Convert.ToDateTime(reader["fecha"]);

                        // Agrego el log a la lista de retorno
                        logs.Add(log);
                    }
                }
            }

            return(logs);
        }
Exemplo n.º 4
0
 public AdminLog(Admin admin, AdminLogTipo tipoLog)
 {
     Admin   = admin;
     TipoLog = tipoLog;
 }