feature: add blazor app
This commit is contained in:
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 });
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user