feature: add blazor app

This commit is contained in:
2025-04-30 00:34:47 +02:00
parent c65e6ac140
commit 57e5119985
33 changed files with 774 additions and 0 deletions

View 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);
}
}
}

View 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 });
}
}
}