CRUD для сборки сделан
This commit is contained in:
parent
b9119331fe
commit
f72779704e
@ -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();
|
||||
@ -188,8 +207,9 @@ namespace HardwareShopWorkerApp.Controllers
|
||||
if (APIClient.User == null)
|
||||
{
|
||||
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>
|
||||
}
|
||||
@ -83,45 +86,71 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal fade" id="updateModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<form method="post" asp-controller="home" asp-action="UpdateBuild">
|
||||
<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 class="modal fade" id="updateModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<form method="post" asp-controller="home" asp-action="UpdateBuild">
|
||||
<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">
|
||||
<label>Name</label>
|
||||
<input type="text" class="form-control" required="required" id="name" name="name" />
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="form-group">
|
||||
<label>Name</label>
|
||||
<input type="text" class="form-control" required="required" id="name" name="name" />
|
||||
</div>
|
||||
</div>
|
||||
<input type="hidden" id="buildId" name="buildId" />
|
||||
<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>
|
||||
<input type="hidden" id="buildId" name="buildId" />
|
||||
<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 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>
|
||||
<script>
|
||||
function update(buildId) {
|
||||
$.ajax({
|
||||
method: "GET",
|
||||
url: "/Home/GetBuild",
|
||||
data: { buildId: buildId },
|
||||
success: function (result) {
|
||||
if (result != null)
|
||||
{
|
||||
$('#name').val(result.buildName);
|
||||
$('#buildId').val(result.id);
|
||||
@section Scripts
|
||||
{
|
||||
<script>
|
||||
function getBuild(buildId) {
|
||||
$.ajax({
|
||||
method: "GET",
|
||||
url: "/Home/GetBuild",
|
||||
data: { buildId: buildId },
|
||||
success: function (result) {
|
||||
if (result != null)
|
||||
{
|
||||
$('#name').val(result.buildName);
|
||||
$('#buildId').val(result.id);
|
||||
$('#deleteBuildId').val(result.id);
|
||||
}
|
||||
console.log(result);
|
||||
}
|
||||
console.log(result);
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
});
|
||||
}
|
||||
</script>
|
||||
}
|
Loading…
Reference in New Issue
Block a user