feature: suche
This commit is contained in:
@@ -56,4 +56,33 @@ public class FahrzeugRepository
|
||||
kommando.Parameters.AddWithValue("@fahrzeug_id", id);
|
||||
kommando.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
public List<FahrzeugDTO> SucheFahrzeuge(string searchTerm)
|
||||
{
|
||||
using var datenbankVerbindung = new MySqlConnection(_connectionString);
|
||||
datenbankVerbindung.Open();
|
||||
|
||||
const string query = "SELECT id, fahrzeug_name, fahrzeug_typ FROM fahrzeuge WHERE fahrzeug_name LIKE @searchTerm OR fahrzeug_typ LIKE @searchTerm;";
|
||||
|
||||
using var kommando = new MySqlCommand(query, datenbankVerbindung);
|
||||
|
||||
kommando.Parameters.AddWithValue("@searchTerm", "%" + searchTerm + "%");
|
||||
|
||||
using var reader = kommando.ExecuteReader();
|
||||
|
||||
List<FahrzeugDTO> fahrzeugs = new();
|
||||
while (reader.Read())
|
||||
{
|
||||
var fahrzeug = new FahrzeugDTO
|
||||
{
|
||||
Id = reader.GetInt32(0),
|
||||
Name = reader.GetString(1),
|
||||
Typ = reader.GetString(2)
|
||||
};
|
||||
|
||||
fahrzeugs.Add(fahrzeug);
|
||||
}
|
||||
|
||||
return fahrzeugs;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user