feature: löschen von objekten

This commit is contained in:
2025-04-30 00:58:16 +02:00
parent 57e5119985
commit 1273aced0c
3 changed files with 28 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
using FahrzeugDatenBank;
using FahrzeugeMVC.Models;
using Microsoft.AspNetCore.Mvc;
using System.Reflection;
namespace FahrzeugeMVC.Controllers;
@@ -44,4 +45,17 @@ public class FahrzeugController : Controller
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));
}
}

View File

@@ -17,6 +17,9 @@
<td>@fahrzeug.Id</td>
<td>@fahrzeug.Name</td>
<td>@fahrzeug.GetType()</td>
<td>
<a asp-action=Loesche asp-controller="Fahrzeug" asp-route-id=@fahrzeug.Id>Löschen</a>
</td>
</tr>
}
</tbody>