feature: add blazor app
This commit is contained in:
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";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
8
FahrzeugDatenBank/FahrzeugDTO.cs
Normal file
8
FahrzeugDatenBank/FahrzeugDTO.cs
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
namespace FahrzeugDatenBank;
|
||||||
|
|
||||||
|
public class FahrzeugDTO
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string? Name { get; set; }
|
||||||
|
public string? Typ { get; set; }
|
||||||
|
}
|
||||||
13
FahrzeugDatenBank/FahrzeugDatenBank.csproj
Normal file
13
FahrzeugDatenBank/FahrzeugDatenBank.csproj
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net9.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="MySqlConnector" Version="2.4.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
48
FahrzeugDatenBank/FahrzeugRepository.cs
Normal file
48
FahrzeugDatenBank/FahrzeugRepository.cs
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
using MySqlConnector;
|
||||||
|
|
||||||
|
namespace FahrzeugDatenBank;
|
||||||
|
|
||||||
|
public class FahrzeugRepository
|
||||||
|
{
|
||||||
|
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 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
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/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";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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>
|
||||||
47
FahrzeugeMVC/Controllers/FahrzeugController.cs
Normal file
47
FahrzeugeMVC/Controllers/FahrzeugController.cs
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
using FahrzeugDatenBank;
|
||||||
|
using FahrzeugeMVC.Models;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace FahrzeugeMVC.Controllers;
|
||||||
|
|
||||||
|
public class FahrzeugController : Controller
|
||||||
|
{
|
||||||
|
public IActionResult Index()
|
||||||
|
{
|
||||||
|
string connectionString = this.GetConnectionString();
|
||||||
|
var respsitory = new FahrzeugRepository(connectionString);
|
||||||
|
List<FahrzeugDTO>? fahrzeugs = respsitory.HoleAlleFahrzeuge();
|
||||||
|
|
||||||
|
var model = new FahrzeugListeModel(fahrzeugs);
|
||||||
|
|
||||||
|
return View(model);
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetConnectionString()
|
||||||
|
{
|
||||||
|
return "Server=localhost;User ID=admin;Password=admin;Database=FahrzeugDB";
|
||||||
|
}
|
||||||
|
|
||||||
|
[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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
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();
|
||||||
|
}
|
||||||
29
FahrzeugeMVC/Program.cs
Normal file
29
FahrzeugeMVC/Program.cs
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
|
// Add services to the container.
|
||||||
|
builder.Services.AddControllersWithViews();
|
||||||
|
|
||||||
|
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/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>
|
||||||
29
FahrzeugeMVC/Views/Fahrzeug/Index.cshtml
Normal file
29
FahrzeugeMVC/Views/Fahrzeug/Index.cshtml
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
@model FahrzeugListeModel
|
||||||
|
|
||||||
|
<p>Diese Fahrzeuge befinden sich derzeit in der Datenbank:</p>
|
||||||
|
|
||||||
|
<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>
|
||||||
|
</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";
|
||||||
|
}
|
||||||
8
FahrzeugeMVC/appsettings.Development.json
Normal file
8
FahrzeugeMVC/appsettings.Development.json
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Microsoft.AspNetCore": "Warning"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
9
FahrzeugeMVC/appsettings.json
Normal file
9
FahrzeugeMVC/appsettings.json
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Microsoft.AspNetCore": "Warning"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"AllowedHosts": "*"
|
||||||
|
}
|
||||||
12
Ubung.sln
12
Ubung.sln
@@ -7,6 +7,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ubung", "Ubung\Ubung.csproj
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SQLMan", "SQLMan\SQLMan.csproj", "{EBEED711-090F-4441-B51E-94F492E920D2}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SQLMan", "SQLMan\SQLMan.csproj", "{EBEED711-090F-4441-B51E-94F492E920D2}"
|
||||||
EndProject
|
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
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@@ -21,6 +25,14 @@ Global
|
|||||||
{EBEED711-090F-4441-B51E-94F492E920D2}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{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.ActiveCfg = Release|Any CPU
|
||||||
{EBEED711-090F-4441-B51E-94F492E920D2}.Release|Any CPU.Build.0 = 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
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|||||||
Reference in New Issue
Block a user