CRUD для сборки сделан
This commit is contained in:
parent
1774b0c758
commit
7ee3f34450
@ -16,13 +16,11 @@ namespace HardwareShopRestApi.Controllers
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IBuildLogic _buildLogic;
|
||||
private readonly IComponentLogic _componentLogic;
|
||||
|
||||
public BuildController(IBuildLogic buildLogic, IComponentLogic componentLogic, ILogger<UserController> logger)
|
||||
public BuildController(IBuildLogic buildLogic, ILogger<UserController> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
_buildLogic = buildLogic;
|
||||
_componentLogic = componentLogic;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
@ -85,11 +83,11 @@ namespace HardwareShopRestApi.Controllers
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void DeleteShop(BuildBindingModel model)
|
||||
public void DeleteBuild(BuildBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_buildLogic.Update(model);
|
||||
_buildLogic.Delete(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -97,19 +95,5 @@ namespace HardwareShopRestApi.Controllers
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void AddDishInShop(ComponentBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_componentLogic.Update(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка компонента в сборку");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -143,6 +143,25 @@ namespace HardwareShopWorkerApp.Controllers
|
||||
Response.Redirect("Builds");
|
||||
}
|
||||
|
||||
|
||||
[HttpPost]
|
||||
public void DeleteBuild(int deleteBuildId)
|
||||
{
|
||||
if (APIClient.User == null)
|
||||
{
|
||||
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||
}
|
||||
if (deleteBuildId <= 0)
|
||||
{
|
||||
throw new Exception($"Идентификтаор сборки не может быть ниже или равен 0");
|
||||
}
|
||||
APIClient.PostRequest("api/build/DeleteBuild", new BuildBindingModel
|
||||
{
|
||||
Id = deleteBuildId,
|
||||
UserId = APIClient.User.Id
|
||||
});
|
||||
Response.Redirect("Builds");
|
||||
}
|
||||
public IActionResult MainWorker()
|
||||
{
|
||||
return View();
|
||||
@ -189,7 +208,8 @@ namespace HardwareShopWorkerApp.Controllers
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
return View(APIClient.GetRequest<List<BuildViewModel>>($"api/build/getbuilds?userId={APIClient.User.Id}"));
|
||||
var list = APIClient.GetRequest<List<BuildViewModel>>($"api/build/getbuilds?userId={APIClient.User.Id}");
|
||||
return View(list);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
|
@ -45,7 +45,10 @@
|
||||
@Html.DisplayFor(modelItem => item.BuildName)
|
||||
</td>
|
||||
<td>
|
||||
<button onclick="update(@item.Id)" type="button" class="btn btn-primary btn-lg mb-5" data-bs-toggle="modal" data-bs-target="#updateModal">Изменить</button>
|
||||
<button onclick="getBuild(@item.Id)" type="button" class="btn btn-primary btn-lg mb-5" data-bs-toggle="modal" data-bs-target="#updateModal">Изменить</button>
|
||||
</td>
|
||||
<td>
|
||||
<button onclick="getBuild(@item.Id)" type="button" class="btn btn-primary btn-lg mb-5" data-bs-toggle="modal" data-bs-target="#deleteModal">Удалить</button>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
@ -106,10 +109,34 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal fade" id="deleteModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<form method="post" asp-controller="home" asp-action="DeleteBuild">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="exampleModalLabel">Удаление сборки</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Закрыть"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="form-group">
|
||||
<h1>Вы уверенны что хотите удалить сборку?</h1>
|
||||
</div>
|
||||
</div>
|
||||
<input type="hidden" id="deleteBuildId" name="deleteBuildId" />
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Закрыть</button>
|
||||
<input type="submit" class="btn btn-primary" value="Удалить">
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
@section Scripts
|
||||
{
|
||||
<script>
|
||||
function update(buildId) {
|
||||
function getBuild(buildId) {
|
||||
$.ajax({
|
||||
method: "GET",
|
||||
url: "/Home/GetBuild",
|
||||
@ -119,9 +146,11 @@
|
||||
{
|
||||
$('#name').val(result.buildName);
|
||||
$('#buildId').val(result.id);
|
||||
$('#deleteBuildId').val(result.id);
|
||||
}
|
||||
console.log(result);
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
}
|
Loading…
Reference in New Issue
Block a user