Compare commits
14 Commits
d87e6dbdac
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 92893665fe | |||
| 8813c83ed9 | |||
| 99640602f5 | |||
| 5b2b05ed55 | |||
| 3f2bd74438 | |||
| 80d64c9574 | |||
| 86006adb9c | |||
| 4e9673b288 | |||
| 63e516fc22 | |||
| 8579b885e1 | |||
| 20303466b6 | |||
| 1273aced0c | |||
| 57e5119985 | |||
| c65e6ac140 |
57
FahrzeugDatenBank/Auto.cs
Normal file
57
FahrzeugDatenBank/Auto.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
|
||||
namespace FahrzeugDatenBank
|
||||
{
|
||||
public class Auto : Fahrzeug, IAuftankbar
|
||||
{
|
||||
public Auto()
|
||||
{
|
||||
base.AnzahlRaeder = 4;
|
||||
base.ReifenTyp = "Sommer";
|
||||
}
|
||||
|
||||
private bool istAufgetankt = false;
|
||||
|
||||
public void Auftanken()
|
||||
{
|
||||
this.istAufgetankt = true;
|
||||
}
|
||||
|
||||
public override void WechsleReifenTyp()
|
||||
{
|
||||
if (base.ReifenTyp == "Sommer")
|
||||
{
|
||||
base.ReifenTyp = "Winter";
|
||||
}
|
||||
else
|
||||
{
|
||||
base.ReifenTyp = "Sommer";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
namespace FahrzeugDatenBank
|
||||
{
|
||||
public class Auto2 : Fahrzeug
|
||||
{
|
||||
public Auto2()
|
||||
{
|
||||
base.AnzahlRaeder = 4;
|
||||
base.ReifenTyp = "Sommer";
|
||||
}
|
||||
|
||||
public override void WechsleReifenTyp()
|
||||
{
|
||||
if (base.ReifenTyp == "Sommer")
|
||||
{
|
||||
base.ReifenTyp = "Winter";
|
||||
}
|
||||
else
|
||||
{
|
||||
base.ReifenTyp = "Sommer";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
25
FahrzeugDatenBank/DatenbankKontext.cs
Normal file
25
FahrzeugDatenBank/DatenbankKontext.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace FahrzeugDatenBank;
|
||||
|
||||
public class DatenbankKontext : DbContext
|
||||
{
|
||||
private readonly string _connectionString;
|
||||
|
||||
public DatenbankKontext(string connectionString)
|
||||
{
|
||||
_connectionString = connectionString;
|
||||
}
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
optionsBuilder.UseMySql(_connectionString, ServerVersion.AutoDetect(_connectionString));
|
||||
}
|
||||
|
||||
public DbSet<FahrzeugDTO> Fahrzeuge { get; set; }
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<FahrzeugDTO>().HasKey(e => e.Id);
|
||||
}
|
||||
}
|
||||
24
FahrzeugDatenBank/Fahrrad.cs
Normal file
24
FahrzeugDatenBank/Fahrrad.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
|
||||
namespace FahrzeugDatenBank
|
||||
{
|
||||
public class Fahrrad : Fahrzeug
|
||||
{
|
||||
public Fahrrad()
|
||||
{
|
||||
base.AnzahlRaeder = 2;
|
||||
base.ReifenTyp = "Strassenreifen";
|
||||
}
|
||||
|
||||
public override void WechsleReifenTyp()
|
||||
{
|
||||
if (base.ReifenTyp == "Strassenreifen")
|
||||
{
|
||||
base.ReifenTyp = "Rennreifen";
|
||||
}
|
||||
else
|
||||
{
|
||||
base.ReifenTyp = "Strassenreifen";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
75
FahrzeugDatenBank/Fahrzeug.cs
Normal file
75
FahrzeugDatenBank/Fahrzeug.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
|
||||
namespace FahrzeugDatenBank
|
||||
{
|
||||
public abstract class Fahrzeug
|
||||
{
|
||||
public Fahrzeug()
|
||||
{
|
||||
this.ReifenTyp = "";
|
||||
}
|
||||
|
||||
public string? Name { get; set; }
|
||||
public int Id { get; set; }
|
||||
|
||||
public int AnzahlRaeder { get; protected set; }
|
||||
|
||||
public string ReifenTyp { get; protected set; }
|
||||
|
||||
public abstract void WechsleReifenTyp();
|
||||
|
||||
public virtual void SetzeAnzahlRaeder(int anzahlDerRaeder)
|
||||
{
|
||||
if (anzahlDerRaeder < 0) return;
|
||||
this.AnzahlRaeder = anzahlDerRaeder;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
namespace FahrzeugDatenBank
|
||||
{
|
||||
public class Fahrzeug2
|
||||
{
|
||||
public Fahrzeug2()
|
||||
{
|
||||
this.SetAnzahlRaeder(4);
|
||||
}
|
||||
|
||||
public Fahrzeug2(int anzahlDerReader)
|
||||
{
|
||||
this.SetAnzahlRaeder(anzahlDerReader);
|
||||
}
|
||||
|
||||
private int anzahlRaeder;
|
||||
|
||||
public int GetAnzahlRaeder()
|
||||
{
|
||||
return this.anzahlRaeder;
|
||||
}
|
||||
|
||||
protected void SetAnzahlRaeder(int anzahlDerReader)
|
||||
{
|
||||
this.anzahlRaeder = anzahlDerReader;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace FahrzeugDatenBank
|
||||
{
|
||||
public class Fahrzeug3
|
||||
{
|
||||
public Fahrzeug3()
|
||||
{
|
||||
this.AnzahlRaeder = 4;
|
||||
}
|
||||
|
||||
public Fahrzeug3(int anzahlDerReader)
|
||||
{
|
||||
this.AnzahlRaeder = anzahlDerReader;
|
||||
}
|
||||
|
||||
public int AnzahlRaeder { get; protected set; }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
14
FahrzeugDatenBank/FahrzeugDTO.cs
Normal file
14
FahrzeugDatenBank/FahrzeugDTO.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace FahrzeugDatenBank;
|
||||
|
||||
[Table("fahrzeuge")]
|
||||
public class FahrzeugDTO
|
||||
{
|
||||
[Column("id")]
|
||||
public int Id { get; set; }
|
||||
[Column("fahrzeug_name")]
|
||||
public string? Name { get; set; }
|
||||
[Column("fahrzeug_typ")]
|
||||
public string? Typ { get; set; }
|
||||
}
|
||||
16
FahrzeugDatenBank/FahrzeugDatenBank.csproj
Normal file
16
FahrzeugDatenBank/FahrzeugDatenBank.csproj
Normal file
@@ -0,0 +1,16 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.17" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.17" />
|
||||
<PackageReference Include="MySqlConnector" Version="2.4.0" />
|
||||
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="8.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
47
FahrzeugDatenBank/FahrzeugOrmRepository.cs
Normal file
47
FahrzeugDatenBank/FahrzeugOrmRepository.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
124
FahrzeugDatenBank/FahrzeugRepository.cs
Normal file
124
FahrzeugDatenBank/FahrzeugRepository.cs
Normal file
@@ -0,0 +1,124 @@
|
||||
using MySqlConnector;
|
||||
|
||||
namespace FahrzeugDatenBank;
|
||||
|
||||
public class FahrzeugRepository : IFahrzeugRepository
|
||||
{
|
||||
private string _connectionString;
|
||||
|
||||
public FahrzeugRepository(string connectionString)
|
||||
{
|
||||
_connectionString = connectionString;
|
||||
}
|
||||
|
||||
public List<FahrzeugDTO> HoleAlleFahrzeuge()
|
||||
{
|
||||
using var datenbankVerbindung = new MySqlConnection(_connectionString);
|
||||
datenbankVerbindung.Open();
|
||||
|
||||
const string query = "SELECT id, fahrzeug_name, fahrzeug_typ FROM fahrzeuge";
|
||||
using var kommando = new MySqlCommand(query, datenbankVerbindung);
|
||||
var reader = kommando.ExecuteReader();
|
||||
|
||||
List<FahrzeugDTO> fahrzeugs = new();
|
||||
while (reader.Read())
|
||||
{
|
||||
var fahrzeug = new FahrzeugDTO();
|
||||
fahrzeug.Id = reader.GetInt32(0);
|
||||
fahrzeug.Name = reader.GetString(1);
|
||||
fahrzeug.Typ = reader.GetString(2);
|
||||
|
||||
fahrzeugs.Add(fahrzeug);
|
||||
}
|
||||
|
||||
return fahrzeugs;
|
||||
}
|
||||
|
||||
public FahrzeugDTO GetFahrzeugByID(int id)
|
||||
{
|
||||
using var datenbankVerbindung = new MySqlConnection(_connectionString);
|
||||
datenbankVerbindung.Open();
|
||||
|
||||
const string query = "SELECT id, fahrzeug_name, fahrzeug_typ FROM fahrzeuge WHERE id = @fahrzeug_id;";
|
||||
using var kommando = new MySqlCommand(query, datenbankVerbindung);
|
||||
kommando.Parameters.AddWithValue("@fahrzeug_id", id);
|
||||
var reader = kommando.ExecuteReader();
|
||||
|
||||
List<FahrzeugDTO> fahrzeugs = new();
|
||||
while (reader.Read())
|
||||
{
|
||||
var fahrzeug = new FahrzeugDTO();
|
||||
fahrzeug.Id = reader.GetInt32(0);
|
||||
fahrzeug.Name = reader.GetString(1);
|
||||
fahrzeug.Typ = reader.GetString(2);
|
||||
|
||||
fahrzeugs.Add(fahrzeug);
|
||||
}
|
||||
|
||||
return fahrzeugs[0];
|
||||
}
|
||||
|
||||
public void FuegeFahrzeugEin(string fahrzeugName, string fahrzeugTyp)
|
||||
{
|
||||
using var datenbankVerbindung = new MySqlConnection(_connectionString);
|
||||
datenbankVerbindung.Open();
|
||||
|
||||
const string query = "INSERT INTO fahrzeuge (fahrzeug_name, fahrzeug_typ)" + "VALUES (@fahrzeug_name, @fahrzeug_typ);";
|
||||
using var kommando = new MySqlCommand(query, datenbankVerbindung);
|
||||
kommando.Parameters.AddWithValue("@fahrzeug_name", fahrzeugName);
|
||||
kommando.Parameters.AddWithValue("@fahrzeug_typ", fahrzeugTyp);
|
||||
kommando.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
public void AktualisiereFahrzeug(int id, string fahrzeugName, string fahrzeugTyp)
|
||||
{
|
||||
using var datenbankVerbindung = new MySqlConnection(_connectionString);
|
||||
datenbankVerbindung.Open();
|
||||
const string query = "UPDATE fahrzeuge SET fahrzeug_name = @fahrzeug_name, fahrzeug_typ = @fahrzeug_typ WHERE id = @id;";
|
||||
using var kommando = new MySqlCommand(query, datenbankVerbindung);
|
||||
kommando.Parameters.AddWithValue("@fahrzeug_name", fahrzeugName);
|
||||
kommando.Parameters.AddWithValue("@fahrzeug_typ", fahrzeugTyp);
|
||||
kommando.Parameters.AddWithValue("@id", id);
|
||||
kommando.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
public void LoescheFahrzeug(int id)
|
||||
{
|
||||
using var datenbankVerbindung = new MySqlConnection(_connectionString);
|
||||
datenbankVerbindung.Open();
|
||||
|
||||
const string query = "DELETE FROM fahrzeuge WHERE id = @fahrzeug_id;";
|
||||
using var kommando = new MySqlCommand(query, datenbankVerbindung);
|
||||
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;
|
||||
}
|
||||
}
|
||||
12
FahrzeugDatenBank/GlobalSuppressions.cs
Normal file
12
FahrzeugDatenBank/GlobalSuppressions.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
// This file is used by Code Analysis to maintain SuppressMessage
|
||||
// attributes that are applied to this project.
|
||||
// Project-level suppressions either have no target or are given
|
||||
// a specific target and scoped to a namespace, type, member, etc.
|
||||
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
[assembly: SuppressMessage("DocumentationHeader", "PropertyDocumentationHeader:The property must have a documentation header.", Justification = "<Ausstehend>", Scope = "module")]
|
||||
[assembly: SuppressMessage("DocumentationHeader", "ConstructorDocumentationHeader:The constructor must have a documentation header.", Justification = "<Ausstehend>", Scope = "module")]
|
||||
[assembly: SuppressMessage("DocumentationHeader", "MethodDocumentationHeader:The method must have a documentation header.", Justification = "<Ausstehend>", Scope = "module")]
|
||||
[assembly: SuppressMessage("DocumentationHeader", "ConstFieldDocumentationHeader:The field must have a documentation header.", Justification = "<Ausstehend>", Scope = "module")]
|
||||
[assembly: SuppressMessage("CodeQuality", "IDE0052:Ungelesene private Member entfernen", Justification = "<Ausstehend>", Scope = "module")]
|
||||
9
FahrzeugDatenBank/IAuftankbar.cs
Normal file
9
FahrzeugDatenBank/IAuftankbar.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
|
||||
namespace FahrzeugDatenBank
|
||||
{
|
||||
public interface IAuftankbar
|
||||
{
|
||||
public void Auftanken();
|
||||
}
|
||||
}
|
||||
|
||||
13
FahrzeugDatenBank/IFahrzeugRepository.cs
Normal file
13
FahrzeugDatenBank/IFahrzeugRepository.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
|
||||
namespace FahrzeugDatenBank
|
||||
{
|
||||
public interface IFahrzeugRepository
|
||||
{
|
||||
void AktualisiereFahrzeug(int id, string fahrzeugName, string fahrzeugTyp);
|
||||
void FuegeFahrzeugEin(string fahrzeugName, string fahrzeugTyp);
|
||||
FahrzeugDTO GetFahrzeugByID(int id);
|
||||
List<FahrzeugDTO> HoleAlleFahrzeuge();
|
||||
void LoescheFahrzeug(int id);
|
||||
List<FahrzeugDTO> SucheFahrzeuge(string searchTerm);
|
||||
}
|
||||
}
|
||||
13
FahrzeugDatenBank/KettenSaege.cs
Normal file
13
FahrzeugDatenBank/KettenSaege.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
|
||||
namespace FahrzeugDatenBank
|
||||
{
|
||||
public class KettenSaege : IAuftankbar
|
||||
{
|
||||
private bool istAufgetankt = false;
|
||||
|
||||
public void Auftanken()
|
||||
{
|
||||
this.istAufgetankt = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
57
FahrzeugDatenBank/Motorrad.cs
Normal file
57
FahrzeugDatenBank/Motorrad.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
|
||||
namespace FahrzeugDatenBank
|
||||
{
|
||||
public class Motorrad : Fahrzeug, IAuftankbar
|
||||
{
|
||||
public Motorrad()
|
||||
{
|
||||
base.AnzahlRaeder = 2;
|
||||
base.ReifenTyp = "schmal";
|
||||
}
|
||||
|
||||
private bool istAufgetankt = false;
|
||||
|
||||
public void Auftanken()
|
||||
{
|
||||
this.istAufgetankt = true;
|
||||
}
|
||||
|
||||
public override void WechsleReifenTyp()
|
||||
{
|
||||
if (base.ReifenTyp == "schmal")
|
||||
{
|
||||
base.ReifenTyp = "breit";
|
||||
}
|
||||
else
|
||||
{
|
||||
base.ReifenTyp = "schmal";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
namespace FahrzeugDatenBank
|
||||
{
|
||||
public class Motorrad2 : Fahrzeug
|
||||
{
|
||||
public Motorrad2()
|
||||
{
|
||||
base.AnzahlRaeder = 2;
|
||||
base.ReifenTyp = "schmal";
|
||||
}
|
||||
|
||||
public override void WechsleReifenTyp()
|
||||
{
|
||||
if (base.ReifenTyp == "schmal")
|
||||
{
|
||||
base.ReifenTyp = "breit";
|
||||
}
|
||||
else
|
||||
{
|
||||
base.ReifenTyp = "schmal";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
25
FahrzeugDatenBankTest/FahrzeugDatenBankTest.csproj
Normal file
25
FahrzeugDatenBankTest/FahrzeugDatenBankTest.csproj
Normal file
@@ -0,0 +1,25 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.2" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
|
||||
<PackageReference Include="xunit" Version="2.9.2" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\FahrzeugDatenBank\FahrzeugDatenBank.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Using Include="Xunit" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
34
FahrzeugDatenBankTest/FahrzeugTest.cs
Normal file
34
FahrzeugDatenBankTest/FahrzeugTest.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using FahrzeugDatenBank;
|
||||
|
||||
namespace FahrzeugDatenBankTest;
|
||||
|
||||
|
||||
public class MyClass
|
||||
{
|
||||
[Fact]
|
||||
public void SetzeAnzahlRaederTest()
|
||||
{
|
||||
// Arrange
|
||||
Fahrzeug fahrzeug = new Auto();
|
||||
int anzahlRaeder = 50;
|
||||
// Act
|
||||
fahrzeug.SetzeAnzahlRaeder(anzahlRaeder);
|
||||
// Assert
|
||||
Assert.Equal(anzahlRaeder, fahrzeug.AnzahlRaeder);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NegativeTest()
|
||||
{
|
||||
// Arrange
|
||||
Fahrzeug fahrzeug = new Auto();
|
||||
int anzahlRaeder = -1;
|
||||
// Act
|
||||
fahrzeug.SetzeAnzahlRaeder(anzahlRaeder);
|
||||
// Assert
|
||||
Assert.Equal(4, fahrzeug.AnzahlRaeder);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
7
FahrzeugVerwaltung/Class1.cs
Normal file
7
FahrzeugVerwaltung/Class1.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace FahrzeugVerwaltung
|
||||
{
|
||||
public class Class1
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
9
FahrzeugVerwaltung/FahrzeugVerwaltung.csproj
Normal file
9
FahrzeugVerwaltung/FahrzeugVerwaltung.csproj
Normal file
@@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
114
FahrzeugeMVC/Controllers/FahrzeugController.cs
Normal file
114
FahrzeugeMVC/Controllers/FahrzeugController.cs
Normal file
@@ -0,0 +1,114 @@
|
||||
using FahrzeugDatenBank;
|
||||
using FahrzeugeMVC.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Reflection;
|
||||
|
||||
namespace FahrzeugeMVC.Controllers;
|
||||
|
||||
public class FahrzeugController : Controller
|
||||
{
|
||||
private readonly IKonfigurationsleser _konfigurationsleser;
|
||||
|
||||
public FahrzeugController(IKonfigurationsleser konfigurationsleser)
|
||||
{
|
||||
_konfigurationsleser = konfigurationsleser;
|
||||
}
|
||||
|
||||
public IActionResult Index(string searchTerm)
|
||||
{
|
||||
string connectionString = this.GetConnectionString();
|
||||
var repository = new FahrzeugRepository(connectionString);
|
||||
|
||||
List<FahrzeugDTO> fahrzeugs;
|
||||
|
||||
if (!string.IsNullOrEmpty(searchTerm))
|
||||
{
|
||||
fahrzeugs = repository.SucheFahrzeuge(searchTerm);
|
||||
}
|
||||
else
|
||||
{
|
||||
fahrzeugs = repository.HoleAlleFahrzeuge();
|
||||
}
|
||||
|
||||
var model = new FahrzeugListeModel(fahrzeugs);
|
||||
return View(model);
|
||||
}
|
||||
|
||||
public string GetConnectionString()
|
||||
{
|
||||
return _konfigurationsleser.LiesDBVerebindung();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Einfuegen()
|
||||
{
|
||||
var model = new FahrzeugEinfugenModel();
|
||||
return View(model);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public IActionResult Einfuegen(FahrzeugEinfugenModel model)
|
||||
{
|
||||
if (ModelState.IsValid && !string.IsNullOrEmpty(model.Name) && !string.IsNullOrEmpty(model.Type))
|
||||
{
|
||||
string connectionString = this.GetConnectionString();
|
||||
var repository = new FahrzeugRepository(connectionString);
|
||||
repository.FuegeFahrzeugEin(model.Name, model.Type);
|
||||
return RedirectToAction(nameof(Index));
|
||||
}
|
||||
else
|
||||
{
|
||||
return View(model);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Aktualisieren(int id)
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
string connectionString = this.GetConnectionString();
|
||||
var repository = new FahrzeugRepository(connectionString);
|
||||
var fahrzeug = repository.GetFahrzeugByID(id);
|
||||
var model = new FahrzeugAktualisierenModel();
|
||||
model.Id = fahrzeug.Id;
|
||||
model.Type = fahrzeug.Typ;
|
||||
model.Name = fahrzeug.Name;
|
||||
return View(model);
|
||||
}
|
||||
else
|
||||
{
|
||||
return View();
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public IActionResult Aktualisieren(FahrzeugAktualisierenModel model)
|
||||
{
|
||||
if (ModelState.IsValid && !string.IsNullOrEmpty(model.Name) && !string.IsNullOrEmpty(model.Type))
|
||||
{
|
||||
string connectionString = this.GetConnectionString();
|
||||
var repository = new FahrzeugRepository(connectionString);
|
||||
int id = (int)model.Id;
|
||||
repository.AktualisiereFahrzeug(id, model.Name, model.Type);
|
||||
return RedirectToAction(nameof(Index));
|
||||
}
|
||||
else
|
||||
{
|
||||
return View(model);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Loesche(int id)
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
string connectionString = this.GetConnectionString();
|
||||
var repository = new FahrzeugRepository(connectionString);
|
||||
repository.LoescheFahrzeug(id);
|
||||
}
|
||||
|
||||
return RedirectToAction(nameof(Index));
|
||||
}
|
||||
}
|
||||
32
FahrzeugeMVC/Controllers/HomeController.cs
Normal file
32
FahrzeugeMVC/Controllers/HomeController.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using FahrzeugeMVC.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace FahrzeugeMVC.Controllers
|
||||
{
|
||||
public class HomeController : Controller
|
||||
{
|
||||
private readonly ILogger<HomeController> _logger;
|
||||
|
||||
public HomeController(ILogger<HomeController> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public IActionResult Index()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
public IActionResult Privacy()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||
public IActionResult Error()
|
||||
{
|
||||
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
||||
}
|
||||
}
|
||||
}
|
||||
13
FahrzeugeMVC/FahrzeugeMVC.csproj
Normal file
13
FahrzeugeMVC/FahrzeugeMVC.csproj
Normal file
@@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\FahrzeugDatenBank\FahrzeugDatenBank.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
9
FahrzeugeMVC/Models/ErrorViewModel.cs
Normal file
9
FahrzeugeMVC/Models/ErrorViewModel.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace FahrzeugeMVC.Models
|
||||
{
|
||||
public class ErrorViewModel
|
||||
{
|
||||
public string? RequestId { get; set; }
|
||||
|
||||
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
|
||||
}
|
||||
}
|
||||
22
FahrzeugeMVC/Models/FahrzeugAktualisierenModel.cs
Normal file
22
FahrzeugeMVC/Models/FahrzeugAktualisierenModel.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using FahrzeugDatenBank;
|
||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace FahrzeugeMVC.Models;
|
||||
|
||||
public class FahrzeugAktualisierenModel
|
||||
{
|
||||
[Required]
|
||||
public int? Id { get; set; }
|
||||
[Required]
|
||||
public string? Name { get; set; }
|
||||
[Required]
|
||||
public string? Type { get; set; }
|
||||
|
||||
public List<SelectListItem> FahrzeugTypen { get; private set; } = new()
|
||||
{
|
||||
new SelectListItem("Auto", "Auto", true),
|
||||
new SelectListItem("Motorrad", "Motorrad"),
|
||||
new SelectListItem("Fahrrad", "Fahrrad")
|
||||
};
|
||||
}
|
||||
19
FahrzeugeMVC/Models/FahrzeugEinfugenModel.cs
Normal file
19
FahrzeugeMVC/Models/FahrzeugEinfugenModel.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace FahrzeugeMVC.Models;
|
||||
|
||||
public class FahrzeugEinfugenModel
|
||||
{
|
||||
[Required]
|
||||
public string? Name { get; set; }
|
||||
[Required]
|
||||
public string? Type { get; set; }
|
||||
|
||||
public List<SelectListItem> FahrzeugTypen { get; private set; } = new()
|
||||
{
|
||||
new SelectListItem("Auto", "Auto", true),
|
||||
new SelectListItem("Motorrad", "Motorrad"),
|
||||
new SelectListItem("Fahrrad", "Fahrrad")
|
||||
};
|
||||
}
|
||||
42
FahrzeugeMVC/Models/FahrzeugListeModel.cs
Normal file
42
FahrzeugeMVC/Models/FahrzeugListeModel.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using FahrzeugDatenBank;
|
||||
|
||||
namespace FahrzeugeMVC.Models;
|
||||
|
||||
public class FahrzeugListeModel
|
||||
{
|
||||
public FahrzeugListeModel(IEnumerable<FahrzeugDTO> fahrzeugs)
|
||||
{
|
||||
foreach (var fahrzeug in fahrzeugs)
|
||||
{
|
||||
switch (fahrzeug.Typ)
|
||||
{
|
||||
case "Auto":
|
||||
var auto = new Auto()
|
||||
{
|
||||
Id = fahrzeug.Id,
|
||||
Name = fahrzeug.Name,
|
||||
};
|
||||
this.Fahrzeuge.Add(auto);
|
||||
break;
|
||||
case "Motorrad":
|
||||
var motorrad = new Motorrad()
|
||||
{
|
||||
Id = fahrzeug.Id,
|
||||
Name = fahrzeug.Name,
|
||||
};
|
||||
this.Fahrzeuge.Add(motorrad);
|
||||
break;
|
||||
case "Fahrrad":
|
||||
var fahrrad = new Fahrrad()
|
||||
{
|
||||
Id = fahrzeug.Id,
|
||||
Name = fahrzeug.Name,
|
||||
};
|
||||
Fahrzeuge.Add(fahrrad);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<Fahrzeug> Fahrzeuge { get; set; } = new();
|
||||
}
|
||||
6
FahrzeugeMVC/Models/IKonfigurationsleser.cs
Normal file
6
FahrzeugeMVC/Models/IKonfigurationsleser.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace FahrzeugeMVC.Models;
|
||||
|
||||
public interface IKonfigurationsleser
|
||||
{
|
||||
string LiesDBVerebindung();
|
||||
}
|
||||
16
FahrzeugeMVC/Models/Konfigurationsleser.cs
Normal file
16
FahrzeugeMVC/Models/Konfigurationsleser.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
namespace FahrzeugeMVC.Models;
|
||||
|
||||
public class Konfigurationsleser : IKonfigurationsleser
|
||||
{
|
||||
private readonly IConfiguration _configuration;
|
||||
|
||||
public Konfigurationsleser(IConfiguration configuration)
|
||||
{
|
||||
this._configuration = configuration;
|
||||
}
|
||||
|
||||
public string LiesDBVerebindung()
|
||||
{
|
||||
return _configuration.GetConnectionString("MariaDB");
|
||||
}
|
||||
}
|
||||
32
FahrzeugeMVC/Program.cs
Normal file
32
FahrzeugeMVC/Program.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using FahrzeugeMVC.Models;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
builder.Services.AddControllersWithViews();
|
||||
builder.Services.AddScoped<IKonfigurationsleser, Konfigurationsleser>();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (!app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseExceptionHandler("/Home/Error");
|
||||
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
|
||||
app.UseHsts();
|
||||
}
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
app.UseRouting();
|
||||
|
||||
app.UseAuthorization();
|
||||
|
||||
app.MapStaticAssets();
|
||||
|
||||
app.MapControllerRoute(
|
||||
name: "default",
|
||||
pattern: "{controller=Home}/{action=Index}/{id?}")
|
||||
.WithStaticAssets();
|
||||
|
||||
|
||||
app.Run();
|
||||
23
FahrzeugeMVC/Properties/launchSettings.json
Normal file
23
FahrzeugeMVC/Properties/launchSettings.json
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/launchsettings.json",
|
||||
"profiles": {
|
||||
"http": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"applicationUrl": "http://localhost:5033",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"https": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"applicationUrl": "https://localhost:7045;http://localhost:5033",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
22
FahrzeugeMVC/Views/Fahrzeug/Aktualisieren.cshtml
Normal file
22
FahrzeugeMVC/Views/Fahrzeug/Aktualisieren.cshtml
Normal file
@@ -0,0 +1,22 @@
|
||||
@model FahrzeugAktualisierenModel
|
||||
|
||||
<p>Aktualisiere das Fahrzeug:</p>
|
||||
|
||||
<form asp-controller="Fahrzeug" asp-action="Aktualisieren">
|
||||
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
|
||||
|
||||
<div>
|
||||
<label class="control-label">Name</label>
|
||||
<input asp-for="Name" class="form-control"/>
|
||||
<span asp-validation-for="Name" class="text-danger"></span>
|
||||
</div>
|
||||
<div>
|
||||
<label class="control-label">Type</label>
|
||||
<select asp-for="Type" asp-items="Model.FahrzeugTypen" class="form-control"></select>
|
||||
<span asp-validation-for="Type" class="text-danger"></span>
|
||||
</div>
|
||||
<br/>
|
||||
<div class="form-group">
|
||||
<input type="submit" value="Submit" class="btn bg-primary" />
|
||||
</div>
|
||||
</form>
|
||||
22
FahrzeugeMVC/Views/Fahrzeug/Einfuegen.cshtml
Normal file
22
FahrzeugeMVC/Views/Fahrzeug/Einfuegen.cshtml
Normal file
@@ -0,0 +1,22 @@
|
||||
@model FahrzeugEinfugenModel
|
||||
|
||||
<p>Fügen sie ein neues Fahrzeug hinzu:</p>
|
||||
|
||||
<form asp-controller="Fahrzeug" asp-action="Einfuegen">
|
||||
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
|
||||
|
||||
<div>
|
||||
<label class="control-label">Name</label>
|
||||
<input asp-for="Name" class="form-control"/>
|
||||
<span asp-validation-for="Name" class="text-danger"></span>
|
||||
</div>
|
||||
<div>
|
||||
<label class="control-label">Type</label>
|
||||
<select asp-for="Type" asp-items="Model.FahrzeugTypen" class="form-control"></select>
|
||||
<span asp-validation-for="Type" class="text-danger"></span>
|
||||
</div>
|
||||
<br/>
|
||||
<div class="form-group">
|
||||
<input type="submit" value="Submit" class="btn bg-primary" />
|
||||
</div>
|
||||
</form>
|
||||
42
FahrzeugeMVC/Views/Fahrzeug/Index.cshtml
Normal file
42
FahrzeugeMVC/Views/Fahrzeug/Index.cshtml
Normal file
@@ -0,0 +1,42 @@
|
||||
@model FahrzeugListeModel
|
||||
|
||||
<p>Diese Fahrzeuge befinden sich derzeit in der Datenbank:</p>
|
||||
|
||||
<form asp-action="Index" asp-controller="Fahrzeug" method="get" class="mb-3">
|
||||
<div class="input-group">
|
||||
<input type="text" name="searchTerm" class="form-control" placeholder="Fahrzeug suchen..." />
|
||||
<button class="btn btn-primary" type="submit">Suchen</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<table class="table table-hover mb-0">
|
||||
<thead>
|
||||
<tr>
|
||||
<td>ID</td>
|
||||
<td>Name</td>
|
||||
<td>Type</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var fahrzeug in Model.Fahrzeuge)
|
||||
{
|
||||
<tr>
|
||||
<td>@fahrzeug.Id</td>
|
||||
<td>@fahrzeug.Name</td>
|
||||
<td>@fahrzeug.GetType()</td>
|
||||
<td>
|
||||
<a asp-action=Aktualisieren asp-controller="Fahrzeug" asp-route-id=@fahrzeug.Id>Aktualisieren</a>
|
||||
</td>
|
||||
<td>
|
||||
<a asp-action=Loesche asp-controller="Fahrzeug" asp-route-id=@fahrzeug.Id>Löschen</a>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<br/>
|
||||
|
||||
<p>
|
||||
@Html.ActionLink("Neues Fahrzeug anlegen", "Einfuegen", "Fahrzeug")
|
||||
</p>
|
||||
8
FahrzeugeMVC/Views/Home/Index.cshtml
Normal file
8
FahrzeugeMVC/Views/Home/Index.cshtml
Normal file
@@ -0,0 +1,8 @@
|
||||
@{
|
||||
ViewData["Title"] = "Home Page";
|
||||
}
|
||||
|
||||
<div class="text-center">
|
||||
<h1 class="display-4">Welcome</h1>
|
||||
<p>Learn about <a href="https://learn.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
|
||||
</div>
|
||||
6
FahrzeugeMVC/Views/Home/Privacy.cshtml
Normal file
6
FahrzeugeMVC/Views/Home/Privacy.cshtml
Normal file
@@ -0,0 +1,6 @@
|
||||
@{
|
||||
ViewData["Title"] = "Privacy Policy";
|
||||
}
|
||||
<h1>@ViewData["Title"]</h1>
|
||||
|
||||
<p>Use this page to detail your site's privacy policy.</p>
|
||||
25
FahrzeugeMVC/Views/Shared/Error.cshtml
Normal file
25
FahrzeugeMVC/Views/Shared/Error.cshtml
Normal file
@@ -0,0 +1,25 @@
|
||||
@model ErrorViewModel
|
||||
@{
|
||||
ViewData["Title"] = "Error";
|
||||
}
|
||||
|
||||
<h1 class="text-danger">Error.</h1>
|
||||
<h2 class="text-danger">An error occurred while processing your request.</h2>
|
||||
|
||||
@if (Model.ShowRequestId)
|
||||
{
|
||||
<p>
|
||||
<strong>Request ID:</strong> <code>@Model.RequestId</code>
|
||||
</p>
|
||||
}
|
||||
|
||||
<h3>Development Mode</h3>
|
||||
<p>
|
||||
Swapping to <strong>Development</strong> environment will display more detailed information about the error that occurred.
|
||||
</p>
|
||||
<p>
|
||||
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
|
||||
It can result in displaying sensitive information from exceptions to end users.
|
||||
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
|
||||
and restarting the app.
|
||||
</p>
|
||||
53
FahrzeugeMVC/Views/Shared/_Layout.cshtml
Normal file
53
FahrzeugeMVC/Views/Shared/_Layout.cshtml
Normal file
@@ -0,0 +1,53 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>@ViewData["Title"] - FahrzeugeMVC</title>
|
||||
<script type="importmap"></script>
|
||||
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
|
||||
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
|
||||
<link rel="stylesheet" href="~/FahrzeugeMVC.styles.css" asp-append-version="true" />
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
|
||||
<div class="container-fluid">
|
||||
<a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index">FahrzeugeMVC</a>
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent"
|
||||
aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
|
||||
<ul class="navbar-nav flex-grow-1">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Index">Home</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Fahrzeug" asp-action="Index">Fahrzeuge</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
</header>
|
||||
<div class="container">
|
||||
<main role="main" class="pb-3">
|
||||
@RenderBody()
|
||||
</main>
|
||||
</div>
|
||||
|
||||
<footer class="border-top footer text-muted">
|
||||
<div class="container">
|
||||
© 2025 - FahrzeugeMVC - <a asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
|
||||
</div>
|
||||
</footer>
|
||||
<script src="~/lib/jquery/dist/jquery.min.js"></script>
|
||||
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="~/js/site.js" asp-append-version="true"></script>
|
||||
@await RenderSectionAsync("Scripts", required: false)
|
||||
</body>
|
||||
</html>
|
||||
48
FahrzeugeMVC/Views/Shared/_Layout.cshtml.css
Normal file
48
FahrzeugeMVC/Views/Shared/_Layout.cshtml.css
Normal file
@@ -0,0 +1,48 @@
|
||||
/* Please see documentation at https://learn.microsoft.com/aspnet/core/client-side/bundling-and-minification
|
||||
for details on configuring this project to bundle and minify static web assets. */
|
||||
|
||||
a.navbar-brand {
|
||||
white-space: normal;
|
||||
text-align: center;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
a {
|
||||
color: #0077cc;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
color: #fff;
|
||||
background-color: #1b6ec2;
|
||||
border-color: #1861ac;
|
||||
}
|
||||
|
||||
.nav-pills .nav-link.active, .nav-pills .show > .nav-link {
|
||||
color: #fff;
|
||||
background-color: #1b6ec2;
|
||||
border-color: #1861ac;
|
||||
}
|
||||
|
||||
.border-top {
|
||||
border-top: 1px solid #e5e5e5;
|
||||
}
|
||||
.border-bottom {
|
||||
border-bottom: 1px solid #e5e5e5;
|
||||
}
|
||||
|
||||
.box-shadow {
|
||||
box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05);
|
||||
}
|
||||
|
||||
button.accept-policy {
|
||||
font-size: 1rem;
|
||||
line-height: inherit;
|
||||
}
|
||||
|
||||
.footer {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
width: 100%;
|
||||
white-space: nowrap;
|
||||
line-height: 60px;
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
<script src="~/lib/jquery-validation/dist/jquery.validate.min.js"></script>
|
||||
<script src="~/lib/jquery-validation-unobtrusive/dist/jquery.validate.unobtrusive.min.js"></script>
|
||||
3
FahrzeugeMVC/Views/_ViewImports.cshtml
Normal file
3
FahrzeugeMVC/Views/_ViewImports.cshtml
Normal file
@@ -0,0 +1,3 @@
|
||||
@using FahrzeugeMVC
|
||||
@using FahrzeugeMVC.Models
|
||||
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
||||
3
FahrzeugeMVC/Views/_ViewStart.cshtml
Normal file
3
FahrzeugeMVC/Views/_ViewStart.cshtml
Normal file
@@ -0,0 +1,3 @@
|
||||
@{
|
||||
Layout = "_Layout";
|
||||
}
|
||||
11
FahrzeugeMVC/appsettings.Development.json
Normal file
11
FahrzeugeMVC/appsettings.Development.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"ConnectionStrings": {
|
||||
"MariaDB": "Server=localhost;User ID=admin;Password=admin;Database=FahrzeugDB"
|
||||
}
|
||||
}
|
||||
12
FahrzeugeMVC/appsettings.json
Normal file
12
FahrzeugeMVC/appsettings.json
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
"ConnectionStrings": {
|
||||
"MariaDB": "Server=localhost;User ID=admin;Password=admin;Database=FahrzeugDB"
|
||||
}
|
||||
}
|
||||
8
FahzeugWPF/App.xaml
Normal file
8
FahzeugWPF/App.xaml
Normal file
@@ -0,0 +1,8 @@
|
||||
<Application x:Class="FahzeugWPF.App"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="clr-namespace:FahzeugWPF">
|
||||
<Application.Resources>
|
||||
|
||||
</Application.Resources>
|
||||
</Application>
|
||||
48
FahzeugWPF/App.xaml.cs
Normal file
48
FahzeugWPF/App.xaml.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using FahrzeugDatenBank;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System.IO;
|
||||
using System.Windows;
|
||||
|
||||
namespace FahzeugWPF
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Interaction logic for App.xaml
|
||||
/// </summary>
|
||||
public partial class App : Application
|
||||
{
|
||||
public static ServiceProvider ServiceProvider { get; private set; }
|
||||
|
||||
public App()
|
||||
{
|
||||
IConfiguration configuration = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json", optional: false, reloadOnChange: true).Build();
|
||||
|
||||
ServiceCollection services = new ServiceCollection();
|
||||
|
||||
services.AddScoped<IKonfigurationsleser>(sp => new Konfigurationsleser(configuration));
|
||||
services.AddScoped(sp => new DatenbankKontext(sp.GetRequiredService<IKonfigurationsleser>().LiesDBVerebindung()));
|
||||
// services.AddScoped<IFahrzeugRepository>(sp => new FahrzeugRepository(sp.GetRequiredService<IKonfigurationsleser>().LiesDBVerebindung()));
|
||||
services.AddScoped<IFahrzeugRepository, FahrzeugOrmRepository>();
|
||||
services.AddScoped<FahrzeugeModell>();
|
||||
services.AddScoped<EinfuegenModel>();
|
||||
services.AddScoped<EinfuegenWindow>();
|
||||
services.AddSingleton<MainWindowViewModel>();
|
||||
services.AddSingleton<MainWindow>();
|
||||
|
||||
ServiceProvider = services.BuildServiceProvider();
|
||||
}
|
||||
|
||||
protected override void OnStartup(StartupEventArgs e)
|
||||
{
|
||||
this.MainWindow = ServiceProvider.GetService<MainWindow>();
|
||||
this.MainWindow.DataContext = ServiceProvider.GetService<MainWindowViewModel>();
|
||||
this.MainWindow.Show();
|
||||
}
|
||||
|
||||
private string GetConnectionString()
|
||||
{
|
||||
return "Server=localhost;User ID=admin;Password=admin;Database=FahrzeugDB";
|
||||
}
|
||||
}
|
||||
}
|
||||
10
FahzeugWPF/AssemblyInfo.cs
Normal file
10
FahzeugWPF/AssemblyInfo.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using System.Windows;
|
||||
|
||||
[assembly: ThemeInfo(
|
||||
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
|
||||
//(used if a resource is not found in the page,
|
||||
// or application resource dictionaries)
|
||||
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
|
||||
//(used if a resource is not found in the page,
|
||||
// app, or any theme specific resource dictionaries)
|
||||
)]
|
||||
29
FahzeugWPF/EinfuegenModel.cs
Normal file
29
FahzeugWPF/EinfuegenModel.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace FahzeugWPF;
|
||||
|
||||
class EinfuegenModel : ViewModelBase
|
||||
{
|
||||
private readonly FahrzeugeModell _fahrzeugeModell;
|
||||
|
||||
public EinfuegenModel(FahrzeugeModell model)
|
||||
{
|
||||
this._fahrzeugeModell = model;
|
||||
EinfuegenKommando = new RelayCommand(Einfugen);
|
||||
}
|
||||
|
||||
public string NeuesrFahrzeugName { get; set; }
|
||||
public string NeuerFahrzeugTyp { get; set; }
|
||||
public ICommand EinfuegenKommando { get; private set; }
|
||||
|
||||
private void Einfugen(object? o)
|
||||
{
|
||||
if (string.IsNullOrEmpty(NeuerFahrzeugTyp) || string.IsNullOrEmpty(NeuesrFahrzeugName)) { return; }
|
||||
_fahrzeugeModell.EinfuegenFahrzeug(NeuesrFahrzeugName, NeuerFahrzeugTyp);
|
||||
if (o is Window window)
|
||||
{
|
||||
window.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
17
FahzeugWPF/EinfuegenWindow.xaml
Normal file
17
FahzeugWPF/EinfuegenWindow.xaml
Normal file
@@ -0,0 +1,17 @@
|
||||
<Window x:Class="FahzeugWPF.EinfuegenWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:FahzeugWPF"
|
||||
mc:Ignorable="d"
|
||||
x:Name="EinfuegenFenster"
|
||||
Title="Fahrzeug Einfuegen" Height="300" Width="500">
|
||||
<StackPanel>
|
||||
<TextBlock Margin="1" Text="Neuse Fahrzeug" VerticalAlignment="Top" />
|
||||
<TextBox HorizontalAlignment="Left" Margin="1" TextWrapping="Wrap" Width="498" Text="{Binding Path=NeuesrFahrzeugName}" />
|
||||
<TextBlock Margin="1" Text="Fahrzeugtyp" VerticalAlignment="Top"/>
|
||||
<TextBox HorizontalAlignment="Left" Margin="1" TextWrapping="Wrap" Width="498" Text="{Binding Path=NeuerFahrzeugTyp}"/>
|
||||
<Button Content="Einfügen" HorizontalAlignment="Left" Margin="1" VerticalAlignment="Top" Command="{Binding Path=EinfuegenKommando}" CommandParameter="{Binding ElementName=EinfuegenFenster}"/>
|
||||
</StackPanel>
|
||||
</Window>
|
||||
27
FahzeugWPF/EinfuegenWindow.xaml.cs
Normal file
27
FahzeugWPF/EinfuegenWindow.xaml.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace FahzeugWPF
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for EinfuegenWindow.xaml
|
||||
/// </summary>
|
||||
public partial class EinfuegenWindow : Window
|
||||
{
|
||||
public EinfuegenWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
55
FahzeugWPF/FahrzeugeModell.cs
Normal file
55
FahzeugWPF/FahrzeugeModell.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using FahrzeugDatenBank;
|
||||
|
||||
namespace FahzeugWPF;
|
||||
|
||||
class FahrzeugeModell
|
||||
{
|
||||
private readonly IFahrzeugRepository _repository;
|
||||
|
||||
public FahrzeugeModell(IFahrzeugRepository repository)
|
||||
{
|
||||
this._repository = repository;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Fahrzeug>> LadeAlleFahrzeuge()
|
||||
{
|
||||
List<FahrzeugDTO>? fahrzeugs = await Task.Run(() =>
|
||||
{
|
||||
return _repository.HoleAlleFahrzeuge();
|
||||
});
|
||||
var fahrzeugListe = KonvertiereFahrzeuge(fahrzeugs);
|
||||
return fahrzeugListe;
|
||||
}
|
||||
|
||||
public void LoescheFahrzeug(Fahrzeug fahrzeug)
|
||||
{
|
||||
_repository.LoescheFahrzeug(fahrzeug.Id);
|
||||
}
|
||||
|
||||
public void EinfuegenFahrzeug(string faName, string faType)
|
||||
{
|
||||
_repository.FuegeFahrzeugEin(faName, faType);
|
||||
}
|
||||
|
||||
private IEnumerable<Fahrzeug> KonvertiereFahrzeuge(IEnumerable<FahrzeugDTO> fahrzeugs)
|
||||
{
|
||||
return fahrzeugs.Select(fahrzeug => KonvertiereFahrzeuf(fahrzeug));
|
||||
}
|
||||
|
||||
private Fahrzeug KonvertiereFahrzeuf(FahrzeugDTO fahrzeugDTO)
|
||||
{
|
||||
switch (fahrzeugDTO.Typ)
|
||||
{
|
||||
case "Auto":
|
||||
var auto = new Auto() { Id = fahrzeugDTO.Id, Name = fahrzeugDTO.Name, };
|
||||
return auto;
|
||||
case "Motorrad":
|
||||
var motorrad = new Motorrad() { Id = fahrzeugDTO.Id, Name = fahrzeugDTO.Name, };
|
||||
return motorrad;
|
||||
case "Fahrrad":
|
||||
var fahrrad = new Fahrrad() { Id = fahrzeugDTO.Id, Name = fahrzeugDTO.Name, };
|
||||
return fahrrad;
|
||||
}
|
||||
throw new Exception($"Unbekannter FahrzeugTyp: {fahrzeugDTO.Typ}");
|
||||
}
|
||||
}
|
||||
31
FahzeugWPF/FahzeugWPF.csproj
Normal file
31
FahzeugWPF/FahzeugWPF.csproj
Normal file
@@ -0,0 +1,31 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net9.0-windows</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<UseWPF>true</UseWPF>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="appsettings.json" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="appsettings.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.5" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.5" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.5" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\FahrzeugDatenBank\FahrzeugDatenBank.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
7
FahzeugWPF/IKonfigurationsleser.cs
Normal file
7
FahzeugWPF/IKonfigurationsleser.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace FahzeugWPF
|
||||
{
|
||||
public interface IKonfigurationsleser
|
||||
{
|
||||
string LiesDBVerebindung();
|
||||
}
|
||||
}
|
||||
18
FahzeugWPF/Konfigurationsleser.cs
Normal file
18
FahzeugWPF/Konfigurationsleser.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace FahzeugWPF;
|
||||
|
||||
public class Konfigurationsleser : IKonfigurationsleser
|
||||
{
|
||||
private readonly IConfiguration _configuration;
|
||||
|
||||
public Konfigurationsleser(IConfiguration configuration)
|
||||
{
|
||||
this._configuration = configuration;
|
||||
}
|
||||
|
||||
public string LiesDBVerebindung()
|
||||
{
|
||||
return _configuration.GetConnectionString("MariaDB");
|
||||
}
|
||||
}
|
||||
39
FahzeugWPF/MainWindow.xaml
Normal file
39
FahzeugWPF/MainWindow.xaml
Normal file
@@ -0,0 +1,39 @@
|
||||
<Window x:Class="FahzeugWPF.MainWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:FahzeugWPF"
|
||||
mc:Ignorable="d"
|
||||
d:DataContext="{d:DesignInstance Type=local:MainWindowViewModel, IsDesignTimeCreatable=False}"
|
||||
Title="{Binding Path=MainWindowTitle}" Height="450" Width="800">
|
||||
<StackPanel>
|
||||
<Menu>
|
||||
<MenuItem Header="Liste">
|
||||
<MenuItem Header="Liste leeren"
|
||||
Command="{Binding Path=LeerenKommando}"/>
|
||||
</MenuItem>
|
||||
<MenuItem Header="Einfügen" Command="{Binding Path=Einfugen}"/>
|
||||
</Menu>
|
||||
<DataGrid x:Name="fahrzeugTabelle"
|
||||
CanUserAddRows="False"
|
||||
CanUserDeleteRows="False"
|
||||
CanUserSortColumns="True"
|
||||
IsReadOnly="True"
|
||||
AutoGenerateColumns="False"
|
||||
ItemsSource="{Binding Path=Fahrzeuge}">
|
||||
<DataGrid.Columns>
|
||||
<DataGridTextColumn Header="ID" Binding="{Binding Path=Id}"/>
|
||||
<DataGridTextColumn Header="Name" Binding="{Binding Path=Name}"/>
|
||||
<DataGridTemplateColumn>
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<Button Command="{Binding ElementName=fahrzeugTabelle, Path=DataContext.LoeschenKommando}" CommandParameter="{Binding}">Löschen</Button>
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
</DataGrid.Columns>
|
||||
|
||||
</DataGrid>
|
||||
</StackPanel>
|
||||
</Window>
|
||||
24
FahzeugWPF/MainWindow.xaml.cs
Normal file
24
FahzeugWPF/MainWindow.xaml.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace FahzeugWPF
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for MainWindow.xaml
|
||||
/// </summary>
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
87
FahzeugWPF/MainWindowViewModel.cs
Normal file
87
FahzeugWPF/MainWindowViewModel.cs
Normal file
@@ -0,0 +1,87 @@
|
||||
using FahrzeugDatenBank;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Timers;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace FahzeugWPF;
|
||||
|
||||
class MainWindowViewModel : ViewModelBase
|
||||
{
|
||||
private readonly FahrzeugeModell _model;
|
||||
private string _mainWindowTitle = "Fahrzeuge";
|
||||
private System.Timers.Timer _timer = new System.Timers.Timer()
|
||||
{
|
||||
Interval = 1000,
|
||||
};
|
||||
|
||||
public MainWindowViewModel(FahrzeugeModell modell)
|
||||
{
|
||||
this._timer.Elapsed += _timer_Elapsed;
|
||||
this._timer.Start();
|
||||
this._model = modell;
|
||||
this.InitialisiereDasViewModell();
|
||||
this.LoeschenKommando = new RelayCommand(LoescheFahrzeug);
|
||||
this.LeerenKommando = new RelayCommand(LeereListe);
|
||||
this.Einfugen = new RelayCommand(EinfugenMachen);
|
||||
}
|
||||
|
||||
public ICommand LoeschenKommando { get; private set; }
|
||||
public ICommand LeerenKommando { get; private set; }
|
||||
public ICommand Einfugen { get; private set; }
|
||||
|
||||
public string MainWindowTitle
|
||||
{
|
||||
get { return _mainWindowTitle; }
|
||||
set
|
||||
{
|
||||
SetProperty<string>(ref _mainWindowTitle, value);
|
||||
}
|
||||
}
|
||||
|
||||
public ObservableCollection<Fahrzeug> Fahrzeuge { get; } = new ObservableCollection<Fahrzeug>();
|
||||
|
||||
private async void InitialisiereDasViewModell()
|
||||
{
|
||||
var fahrzeuge = await _model.LadeAlleFahrzeuge();
|
||||
foreach (var fahrzeug in fahrzeuge)
|
||||
{
|
||||
this.Fahrzeuge.Add(fahrzeug);
|
||||
}
|
||||
}
|
||||
|
||||
private void _timer_Elapsed(object? sender, ElapsedEventArgs e)
|
||||
{
|
||||
this.MainWindowTitle = $"Fahrzeuge {DateTime.Now.ToLongTimeString()}";
|
||||
}
|
||||
|
||||
private void LoescheFahrzeug(object? fahrzeug)
|
||||
{
|
||||
if (fahrzeug == null)
|
||||
return;
|
||||
_model.LoescheFahrzeug((Fahrzeug)fahrzeug);
|
||||
this.Fahrzeuge.Remove((Fahrzeug)fahrzeug);
|
||||
}
|
||||
|
||||
private async void LeereListe(object? o)
|
||||
{
|
||||
await Task.Run(() =>
|
||||
{
|
||||
Application.Current.Dispatcher.Invoke(() =>
|
||||
{
|
||||
this.Fahrzeuge.Clear();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
private void EinfugenMachen(object? o)
|
||||
{
|
||||
var einfuege = App.ServiceProvider.GetService<EinfuegenWindow>();
|
||||
einfuege.DataContext = App.ServiceProvider.GetService<EinfuegenModel>();
|
||||
einfuege.ShowDialog();
|
||||
|
||||
LeereListe(o);
|
||||
InitialisiereDasViewModell();
|
||||
}
|
||||
}
|
||||
44
FahzeugWPF/RelayCommand.cs
Normal file
44
FahzeugWPF/RelayCommand.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
namespace FahzeugWPF;
|
||||
|
||||
using System.Diagnostics;
|
||||
using System.Windows.Input;
|
||||
|
||||
public class RelayCommand : ICommand
|
||||
{
|
||||
readonly Action<object> _execute = null;
|
||||
readonly Predicate<object> _canExecute = null;
|
||||
|
||||
public RelayCommand(Action<object> execute)
|
||||
: this(execute, null)
|
||||
{
|
||||
// Nothing to do
|
||||
}
|
||||
|
||||
public RelayCommand(Action<object> execute, Predicate<object> canExecute)
|
||||
{
|
||||
if (execute == null)
|
||||
{
|
||||
throw new ArgumentNullException("execute");
|
||||
}
|
||||
|
||||
this._execute = execute;
|
||||
this._canExecute = canExecute;
|
||||
}
|
||||
|
||||
[DebuggerStepThrough]
|
||||
public bool CanExecute(object parameter)
|
||||
{
|
||||
return _canExecute == null ? true : _canExecute(parameter);
|
||||
}
|
||||
|
||||
public event EventHandler CanExecuteChanged
|
||||
{
|
||||
add { CommandManager.RequerySuggested += value; }
|
||||
remove { CommandManager.RequerySuggested -= value; }
|
||||
}
|
||||
|
||||
public void Execute(object parameter)
|
||||
{
|
||||
_execute(parameter);
|
||||
}
|
||||
}
|
||||
60
FahzeugWPF/ViewModelBase.cs
Normal file
60
FahzeugWPF/ViewModelBase.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
namespace FahzeugWPF;
|
||||
|
||||
using System.ComponentModel;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
public abstract class ViewModelBase : INotifyPropertyChanged
|
||||
{
|
||||
#region Events
|
||||
|
||||
[field: NonSerialized]
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
protected void OnPropertyChanged(Expression<Func<object>> expression)
|
||||
{
|
||||
var lambdaExpression = expression as LambdaExpression;
|
||||
|
||||
MemberExpression memberExpression = null;
|
||||
if (lambdaExpression.Body is UnaryExpression)
|
||||
{
|
||||
var unaryExpression = lambdaExpression.Body as UnaryExpression;
|
||||
memberExpression = unaryExpression.Operand as MemberExpression;
|
||||
}
|
||||
else
|
||||
{
|
||||
memberExpression = lambdaExpression.Body as MemberExpression;
|
||||
}
|
||||
|
||||
if (memberExpression != null)
|
||||
{
|
||||
var propertyInfo = memberExpression.Member as PropertyInfo;
|
||||
if (propertyInfo != null)
|
||||
{
|
||||
OnPropertyChanged(propertyInfo.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
|
||||
{
|
||||
if (PropertyChanged != null)
|
||||
{
|
||||
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
}
|
||||
|
||||
protected bool SetProperty<T>(ref T field, T value, [CallerMemberName] string? propertyName = null)
|
||||
{
|
||||
if (EqualityComparer<T>.Default.Equals(field, value))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
field = value;
|
||||
OnPropertyChanged(propertyName);
|
||||
return true;
|
||||
}
|
||||
#endregion Events
|
||||
}
|
||||
5
FahzeugWPF/appsettings.json
Normal file
5
FahzeugWPF/appsettings.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"ConnectionStrings": {
|
||||
"MariaDB": "Server=localhost;User ID=admin;Password=admin;Database=FahrzeugDB"
|
||||
}
|
||||
}
|
||||
10
Multi/Multi.csproj
Normal file
10
Multi/Multi.csproj
Normal file
@@ -0,0 +1,10 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
68
Multi/Program.cs
Normal file
68
Multi/Program.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
|
||||
using Multi;
|
||||
|
||||
|
||||
// Aufgabe 1
|
||||
void Arbeiten()
|
||||
{
|
||||
for (int i = 0; i <= 10; i++)
|
||||
{
|
||||
Console.WriteLine(Thread.CurrentThread.Name + $"; {i}");
|
||||
Thread.Sleep(1);
|
||||
}
|
||||
}
|
||||
|
||||
Thread thread = new Thread(() => Arbeiten());
|
||||
Thread thread1 = new Thread(Arbeiten);
|
||||
Thread thread2 = new Thread(Arbeiten);
|
||||
|
||||
thread.Name = "Test";
|
||||
thread1.Name = "Test1";
|
||||
thread2.Name = "Test2";
|
||||
|
||||
thread.Start();
|
||||
thread1.Start();
|
||||
thread2.Start();
|
||||
|
||||
// Aufgabe 2
|
||||
|
||||
SimpleTaskProgram simpleTaskProgram = new();
|
||||
simpleTaskProgram.Start();
|
||||
|
||||
// Aufgabe 3
|
||||
|
||||
string Arbeiten1(string name)
|
||||
{
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
Console.WriteLine($"{name}: {i}");
|
||||
Task.Delay(1).Wait();
|
||||
}
|
||||
|
||||
return "erledigt";
|
||||
}
|
||||
|
||||
async Task<string> Methode()
|
||||
{
|
||||
return await Task.Run(() => Arbeiten1("Methode"));
|
||||
}
|
||||
|
||||
async Task<string> Methode1()
|
||||
{
|
||||
await Methode();
|
||||
return await Task.Run(() => Arbeiten1("Methode1"));
|
||||
}
|
||||
|
||||
async Task<string> Methode2()
|
||||
{
|
||||
return await Task.Run(() => Arbeiten1("Methode2"));
|
||||
}
|
||||
|
||||
Task task = Methode();
|
||||
var task1 = Methode1();
|
||||
var task2 = Methode2();
|
||||
|
||||
await task;
|
||||
await task1;
|
||||
await task2;
|
||||
|
||||
31
Multi/SimpleTaskProgram.cs
Normal file
31
Multi/SimpleTaskProgram.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
namespace Multi;
|
||||
|
||||
internal class SimpleTaskProgram
|
||||
{
|
||||
public void Start()
|
||||
{
|
||||
Methode1();
|
||||
Methode2();
|
||||
}
|
||||
|
||||
public async Task Methode1()
|
||||
{
|
||||
await Task.Run(() =>
|
||||
{
|
||||
for (int i = 0; i < 25; i++)
|
||||
{
|
||||
Console.WriteLine("Methode 1");
|
||||
Task.Delay(100).Wait();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void Methode2()
|
||||
{
|
||||
for (int i = 0; i < 25; i++)
|
||||
{
|
||||
Console.WriteLine("Methode 2");
|
||||
Task.Delay(100).Wait();
|
||||
}
|
||||
}
|
||||
}
|
||||
30
Ubung.sln
30
Ubung.sln
@@ -7,6 +7,16 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ubung", "Ubung\Ubung.csproj
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SQLMan", "SQLMan\SQLMan.csproj", "{EBEED711-090F-4441-B51E-94F492E920D2}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FahrzeugeMVC", "FahrzeugeMVC\FahrzeugeMVC.csproj", "{9E183977-78A1-40F3-87F9-130222AD8271}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FahrzeugDatenBank", "FahrzeugDatenBank\FahrzeugDatenBank.csproj", "{34C040B0-819F-4DF8-94FD-77A6A037F957}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Multi", "Multi\Multi.csproj", "{F89339C1-2589-428A-82D6-6799A875C421}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FahrzeugDatenBankTest", "FahrzeugDatenBankTest\FahrzeugDatenBankTest.csproj", "{9C442F96-64F6-4CEA-AB7F-2B28BF578471}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FahzeugWPF", "FahzeugWPF\FahzeugWPF.csproj", "{BB365A73-CB9B-471A-BDBE-02843D8C72A3}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -21,6 +31,26 @@ Global
|
||||
{EBEED711-090F-4441-B51E-94F492E920D2}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{EBEED711-090F-4441-B51E-94F492E920D2}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{EBEED711-090F-4441-B51E-94F492E920D2}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{9E183977-78A1-40F3-87F9-130222AD8271}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{9E183977-78A1-40F3-87F9-130222AD8271}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{9E183977-78A1-40F3-87F9-130222AD8271}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{9E183977-78A1-40F3-87F9-130222AD8271}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{34C040B0-819F-4DF8-94FD-77A6A037F957}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{34C040B0-819F-4DF8-94FD-77A6A037F957}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{34C040B0-819F-4DF8-94FD-77A6A037F957}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{34C040B0-819F-4DF8-94FD-77A6A037F957}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{F89339C1-2589-428A-82D6-6799A875C421}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{F89339C1-2589-428A-82D6-6799A875C421}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{F89339C1-2589-428A-82D6-6799A875C421}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{F89339C1-2589-428A-82D6-6799A875C421}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{9C442F96-64F6-4CEA-AB7F-2B28BF578471}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{9C442F96-64F6-4CEA-AB7F-2B28BF578471}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{9C442F96-64F6-4CEA-AB7F-2B28BF578471}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{9C442F96-64F6-4CEA-AB7F-2B28BF578471}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{BB365A73-CB9B-471A-BDBE-02843D8C72A3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{BB365A73-CB9B-471A-BDBE-02843D8C72A3}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{BB365A73-CB9B-471A-BDBE-02843D8C72A3}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{BB365A73-CB9B-471A-BDBE-02843D8C72A3}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
@@ -50,7 +50,7 @@ Console.WriteLine(genList2.GetValue(1));
|
||||
var rand = new Random();
|
||||
List<int> list = new();
|
||||
|
||||
for (int i = 0; i < 100; i++)
|
||||
for (int i = 0; i < 1000; i++)
|
||||
{
|
||||
list.Add(rand.Next(101));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user