Delete method for component

This commit is contained in:
the 2023-04-09 12:04:14 +04:00
parent 63f4dbe428
commit 7487437504
4 changed files with 54 additions and 0 deletions

View File

@ -179,6 +179,26 @@ namespace ComputerShopClientApp.Controllers
Response.Redirect("Index");
}
[HttpGet]
public IActionResult DeleteComponent()
{
ViewBag.Components = APIClient.GetRequest<List<ComponentViewModel>>("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()
{

View File

@ -22,6 +22,9 @@
<p>
<a asp-action="CreateComponent">Создать комплектующее</a>
</p>
<p>
<a asp-action="DeleteComponent">Удалить комплектующее</a>
</p>
<table class="table">
<thead>
<tr>

View File

@ -0,0 +1,18 @@
@{
ViewData["Title"] = "DeleteComponent";
}
<div class="text-center">
<h2 class="display-4">Удаление компонента</h2>
</div>
<form method="post">
<div class="row">
<div class="col-4">Компонент:</div>
<div class="col-8">
<select id="component" name="component" class="form-control" asp-items="@(new SelectList(@ViewBag.Components,"Id", "ComponentName"))"></select>
</div>
</div>
<div class="row">
<div class="col-8"></div>
<div class="col-4"><input type="submit" value="Удалить" class="btn btn-primary" /></div>
</div>
</form>

View File

@ -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;
}
}
}
}