From 748743750498d631f0b0d4a9718fda81b156d815 Mon Sep 17 00:00:00 2001 From: the Date: Sun, 9 Apr 2023 12:04:14 +0400 Subject: [PATCH] Delete method for component --- .../Controllers/HomeController.cs | 20 +++++++++++++++++++ .../Views/Home/Component.cshtml | 3 +++ .../Views/Home/DeleteComponent.cshtml | 18 +++++++++++++++++ .../Controllers/ComponentController.cs | 13 ++++++++++++ 4 files changed, 54 insertions(+) create mode 100644 ComputerShopProvider/ComputerShopClientApp/Views/Home/DeleteComponent.cshtml diff --git a/ComputerShopProvider/ComputerShopClientApp/Controllers/HomeController.cs b/ComputerShopProvider/ComputerShopClientApp/Controllers/HomeController.cs index 58a47bd..aae16f4 100644 --- a/ComputerShopProvider/ComputerShopClientApp/Controllers/HomeController.cs +++ b/ComputerShopProvider/ComputerShopClientApp/Controllers/HomeController.cs @@ -179,6 +179,26 @@ namespace ComputerShopClientApp.Controllers Response.Redirect("Index"); } + [HttpGet] + public IActionResult DeleteComponent() + { + ViewBag.Components = APIClient.GetRequest>("api/main/getcomponentlist"); + return View(); + } + [HttpDelete] + public void DeleteComponent(int component) + { + if (APIClient.Client == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + APIClient.PostRequest("api/component/deletecomponent", new ComponentBindingModel + { + Id = component + }); + Response.Redirect("Index"); + } + [HttpGet] public IActionResult CreateAssembly() { diff --git a/ComputerShopProvider/ComputerShopClientApp/Views/Home/Component.cshtml b/ComputerShopProvider/ComputerShopClientApp/Views/Home/Component.cshtml index 32c1348..eb71419 100644 --- a/ComputerShopProvider/ComputerShopClientApp/Views/Home/Component.cshtml +++ b/ComputerShopProvider/ComputerShopClientApp/Views/Home/Component.cshtml @@ -22,6 +22,9 @@

Создать комплектующее

+

+ Удалить комплектующее +

diff --git a/ComputerShopProvider/ComputerShopClientApp/Views/Home/DeleteComponent.cshtml b/ComputerShopProvider/ComputerShopClientApp/Views/Home/DeleteComponent.cshtml new file mode 100644 index 0000000..87c1183 --- /dev/null +++ b/ComputerShopProvider/ComputerShopClientApp/Views/Home/DeleteComponent.cshtml @@ -0,0 +1,18 @@ +@{ + ViewData["Title"] = "DeleteComponent"; +} +
+

Удаление компонента

+
+ +
+
Компонент:
+
+ +
+
+
+
+
+
+ \ No newline at end of file diff --git a/ComputerShopProvider/ComputerShopRestApi/Controllers/ComponentController.cs b/ComputerShopProvider/ComputerShopRestApi/Controllers/ComponentController.cs index 2b2d379..91e20b1 100644 --- a/ComputerShopProvider/ComputerShopRestApi/Controllers/ComponentController.cs +++ b/ComputerShopProvider/ComputerShopRestApi/Controllers/ComponentController.cs @@ -43,5 +43,18 @@ namespace ComputerShopRestApi.Controllers throw; } } + [HttpDelete] + public void DeleteComponent(ComponentBindingModel model) + { + try + { + _component.Delete(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления компонента"); + throw; + } + } } }