48 lines
1.3 KiB
C#
48 lines
1.3 KiB
C#
|
|
namespace FahrzeugDatenBank;
|
|
|
|
public class FahrzeugOrmRepository : IFahrzeugRepository
|
|
{
|
|
private readonly DatenbankKontext _kontext;
|
|
|
|
public FahrzeugOrmRepository(DatenbankKontext kontext)
|
|
{
|
|
this._kontext = kontext;
|
|
}
|
|
|
|
public void AktualisiereFahrzeug(int id, string fahrzeugName, string fahrzeugTyp)
|
|
{
|
|
FahrzeugDTO fahrzeug = _kontext.Fahrzeuge.First(f => f.Id == id);
|
|
fahrzeug.Name = fahrzeugName;
|
|
fahrzeug.Typ = fahrzeugTyp;
|
|
_kontext.SaveChanges();
|
|
}
|
|
|
|
public void FuegeFahrzeugEin(string fahrzeugName, string fahrzeugTyp)
|
|
{
|
|
_kontext.Fahrzeuge.Add(new FahrzeugDTO() { Name = fahrzeugName, Typ = fahrzeugTyp });
|
|
_kontext.SaveChanges();
|
|
}
|
|
|
|
public FahrzeugDTO GetFahrzeugByID(int id)
|
|
{
|
|
return _kontext.Fahrzeuge.First(f => f.Id == id);
|
|
}
|
|
|
|
public List<FahrzeugDTO> HoleAlleFahrzeuge()
|
|
{
|
|
return _kontext.Fahrzeuge.ToList();
|
|
}
|
|
|
|
public void LoescheFahrzeug(int id)
|
|
{
|
|
_kontext.Fahrzeuge.Remove(GetFahrzeugByID(id));
|
|
_kontext.SaveChanges();
|
|
}
|
|
|
|
public List<FahrzeugDTO> SucheFahrzeuge(string searchTerm)
|
|
{
|
|
return _kontext.Fahrzeuge.Where(f => f.Name.Contains(searchTerm) || f.Typ.Contains(searchTerm)).ToList();
|
|
}
|
|
}
|