реализовал редактирование сборки
This commit is contained in:
parent
4121d5ec1c
commit
b9119331fe
@ -43,11 +43,11 @@ namespace HardwareShopRestApi.Controllers
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public BuildViewModel? GetBuild(int id)
|
||||
public BuildViewModel? GetBuild(int buildId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _buildLogic.ReadElement(new() { Id = id });
|
||||
return _buildLogic.ReadElement(new() { Id = buildId });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -1,4 +1,5 @@
|
||||
using HardwareShopContracts.BindingModels;
|
||||
using HardwareShopContracts.SearchModels;
|
||||
using HardwareShopContracts.ViewModels;
|
||||
using HardwareShopDatabaseImplement.Models;
|
||||
using HardwareShopDataModels.Enums;
|
||||
@ -99,8 +100,27 @@ namespace HardwareShopWorkerApp.Controllers
|
||||
Response.Redirect("Builds");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public BuildViewModel GetBuild(int buildId)
|
||||
{
|
||||
if (APIClient.User == null)
|
||||
{
|
||||
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||
}
|
||||
if (buildId <= 0)
|
||||
{
|
||||
throw new Exception($"Идентификтаор сборки не может быть ниже или равен 0");
|
||||
}
|
||||
var result = APIClient.GetRequest<BuildViewModel>($"api/build/getBuild?buildId={buildId}");
|
||||
if (result == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void UpdateBuild(string name)
|
||||
public void UpdateBuild(string name, int buildId)
|
||||
{
|
||||
if (APIClient.User == null)
|
||||
{
|
||||
@ -108,10 +128,15 @@ namespace HardwareShopWorkerApp.Controllers
|
||||
}
|
||||
if (string.IsNullOrEmpty(name))
|
||||
{
|
||||
throw new Exception($"Имя магазина не должно быть пустым");
|
||||
throw new Exception($"Имя сборки не должно быть пустым");
|
||||
}
|
||||
if (buildId <= 0)
|
||||
{
|
||||
throw new Exception($"Идентификтаор сборки не может быть ниже или равен 0");
|
||||
}
|
||||
APIClient.PostRequest("api/build/update", new BuildBindingModel
|
||||
{
|
||||
Id = buildId,
|
||||
BuildName = name,
|
||||
UserId = APIClient.User.Id
|
||||
});
|
||||
|
@ -44,6 +44,9 @@
|
||||
<td>
|
||||
@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>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
@ -83,7 +86,7 @@
|
||||
<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="update">
|
||||
<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>
|
||||
@ -91,9 +94,10 @@
|
||||
<div class="modal-body">
|
||||
<div class="form-group">
|
||||
<label>Name</label>
|
||||
<input type="text" class="form-control" required="required" name="name" />
|
||||
<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="Сохранить">
|
||||
@ -104,3 +108,20 @@
|
||||
</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);
|
||||
}
|
||||
console.log(result);
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
Loading…
Reference in New Issue
Block a user