From b20759f20589af855adb977079cf77b4ef299b13 Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Thu, 16 Feb 2023 08:46:04 +0300 Subject: [PATCH] Add delete action for bundles controller --- Controllers/BundlesController.cs | 10 ++++++++++ Views/Bundles/Index.cshtml | 2 ++ 2 files changed, 12 insertions(+) diff --git a/Controllers/BundlesController.cs b/Controllers/BundlesController.cs index 8b66139..1f5c212 100644 --- a/Controllers/BundlesController.cs +++ b/Controllers/BundlesController.cs @@ -22,5 +22,15 @@ namespace MyDarling.Controllers { return View(repository.Bundles.Where(b => b.Id == id).FirstOrDefault()); } + + public ActionResult Delete(int id) + { + var bundle = repository.Bundles.Where(b => b.Id == id).FirstOrDefault(); + if (bundle != null) + { + repository.Remove(bundle); + } + return RedirectToAction("Index"); + } } } \ No newline at end of file diff --git a/Views/Bundles/Index.cshtml b/Views/Bundles/Index.cshtml index 6c36cb7..e93edb2 100644 --- a/Views/Bundles/Index.cshtml +++ b/Views/Bundles/Index.cshtml @@ -18,6 +18,7 @@ Name Descrition Price + Actions @@ -28,6 +29,7 @@ @bundle.Name @bundle.Description @bundle.Price + Delete }