feature: löschen von objekten
This commit is contained in:
@@ -45,4 +45,15 @@ public class FahrzeugRepository
|
|||||||
kommando.Parameters.AddWithValue("@fahrzeug_typ", fahrzeugTyp);
|
kommando.Parameters.AddWithValue("@fahrzeug_typ", fahrzeugTyp);
|
||||||
kommando.ExecuteNonQuery();
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using FahrzeugDatenBank;
|
using FahrzeugDatenBank;
|
||||||
using FahrzeugeMVC.Models;
|
using FahrzeugeMVC.Models;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
namespace FahrzeugeMVC.Controllers;
|
namespace FahrzeugeMVC.Controllers;
|
||||||
|
|
||||||
@@ -44,4 +45,17 @@ public class FahrzeugController : Controller
|
|||||||
return View(model);
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,9 @@
|
|||||||
<td>@fahrzeug.Id</td>
|
<td>@fahrzeug.Id</td>
|
||||||
<td>@fahrzeug.Name</td>
|
<td>@fahrzeug.Name</td>
|
||||||
<td>@fahrzeug.GetType()</td>
|
<td>@fahrzeug.GetType()</td>
|
||||||
|
<td>
|
||||||
|
<a asp-action=Loesche asp-controller="Fahrzeug" asp-route-id=@fahrzeug.Id>Löschen</a>
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
}
|
}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|||||||
Reference in New Issue
Block a user