Exemple #1
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);
        }
Exemple #2
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);
        }