This commit is contained in:
dasha 2023-05-16 17:52:38 +04:00
parent 011fa8a2c3
commit f8845a84c0
9 changed files with 2449 additions and 24 deletions

View File

@ -1,5 +1,6 @@
using HardwareShopContracts.BindingModels;
using HardwareShopContracts.ViewModels;
using HardwareShopDatabaseImplement.Models;
using HardwareShopDataModels.Enums;
using Microsoft.AspNetCore.Mvc;
@ -52,7 +53,6 @@ namespace HardwareShopStorekeeperApp.Controllers
Response.Redirect("Orders");
}
[HttpPost]
public void DeleteOrder(int Id)
{
@ -189,6 +189,52 @@ namespace HardwareShopStorekeeperApp.Controllers
return result;
}
[HttpPost]
public void UpdateComponent(string name, string cost, DateTime date, int component)
{
if (APIClient.User == null)
{
throw new Exception("Вы как сюда попали? Сюда вход только авторизованным");
}
if (component <= 0)
{
throw new Exception($"Идентификтаор комплектующего не может быть меньше или равен 0");
}
if (string.IsNullOrEmpty(name))
{
throw new Exception($"Имя комплектующего не должно быть пустым");
}
if (Convert.ToDouble(cost.Replace('.', ',')) <= 0)
{
throw new Exception($"Цена комплектующего не может быть меньше или равна 0");
}
APIClient.PostRequest("api/component/updatedata", new ComponentBindingModel
{
Id = component,
ComponentName = name,
Cost = Convert.ToDouble(cost.Replace('.', ',')),
UserId = APIClient.User.Id,
});
Response.Redirect("Components");
}
[HttpPost]
public void DeleteComponent(int component)
{
if (APIClient.User == null)
{
throw new Exception("Вы как сюда попали? Сюда вход только авторизованным");
}
if (component <= 0)
{
throw new Exception($"Идентификтаор комплектующего не может быть меньше или равен 0");
}
APIClient.PostRequest("api/component/deletecomponent", new ComponentBindingModel
{
Id = component
});
}
public IActionResult MainStorekeeper()
{
if (APIClient.User == null)

View File

@ -7,6 +7,7 @@
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
<link rel="stylesheet" href="~/HardwareShopStorekeeperApp.styles.css" asp-append-version="true" />
<link rel="stylesheet" href="~/lib/font-awesome-4.7.0/css/font-awesome.min.css">
</head>
<body>
@RenderSection("Header")

View File

@ -7,6 +7,7 @@
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
<link rel="stylesheet" href="~/HardwareShopStorekeeperApp.styles.css" asp-append-version="true" />
<link rel="stylesheet" href="~/lib/font-awesome-4.7.0/css/font-awesome.min.css">
@await RenderSectionAsync("Styles", required: false)
</head>
<body>

View File

@ -16,8 +16,6 @@
@{
<p>
<a asp-action="CreateComponent" class="btn btn-primary mx-2">Создать комплектующее</a>
<button type="button" class="btn btn-primary mx-2" data-bs-toggle="modal" data-bs-target="#exampleModal">Изменить комплектующее</button>
<button type="button" class="btn btn-primary mx-2">Удалить комплектующее</button>
<a asp-action="LinkBuilds" class="btn btn-primary mx-2">Привязка сборок</a>
</p>
<table class="table">
@ -32,6 +30,9 @@
<th>
Дата приобретения
</th>
<th>
Действия
</th>
</tr>
</thead>
<tbody>
@ -47,6 +48,16 @@
<td>
@Html.DisplayFor(modelItem => item.DateCreate)
</td>
<td>
<div>
<button onclick="getComponent(@item.Id)" type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#updateModal">
<i class="fa fa-pencil" aria-hidden="true"></i>
</button>
<button onclick="deleteComponent(@item.Id)" type="button" class="btn btn-danger">
<i class="fa fa-trash" aria-hidden="true"></i>
</button>
</div>
</td>
</tr>
}
</tbody>
@ -54,33 +65,58 @@
}
</div>
<form method="post" class="d-flex flex-column align-items-center">
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<form method="post" asp-controller="Storekeeper" asp-action="UpdateComponent">
<div class="modal fade" id="updateModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Изменение комплектующего</h5>
<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="col">
<label class="form-label">Название</label>
<input type="text" class="form-control" name="email">
<input type="text" class="form-control" name="name" id="name" required>
</div>
<div class="col">
<label class="form-label">Стоимость</label>
<input type="number" step="0.01" class="form-control" name="cost" min="0.01">
</div>
<div class="col">
<label class="form-label">Дата приобретения</label>
<input type="date" class="form-control" name="date">
<input type="number" step="0.01" class="form-control" name="cost" id="cost" min="0.01" required>
</div>
</div>
<input type="hidden" id="component" name="component" />
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Закрыть</button>
<button type="submit" class="btn btn-primary">Сохранить</button>
<input type="submit" class="btn btn-primary" value="Сохранить">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Отмена</button>
</div>
</div>
</div>
</div>
</form>
@section Scripts
{
<script>
function getComponent(componentId) {
$.ajax({
method: "GET",
url: "/Storekeeper/GetComponent",
data: { Id: componentId },
success: function (result) {
if (result != null)
{
$('#name').val(result.componentName);
$('#cost').val(result.cost);
$('#component').val(result.id);
}
}
});
}
function deleteComponent(componentId) {
$.ajax({
method: "POST",
url: "/Storekeeper/DeleteComponent",
data: { component: componentId }
}).done(() => window.location.href = "/Storekeeper/Components");
}
</script>
}

View File

@ -18,7 +18,7 @@
</div>
<div class="col-sm-3">
<label class="form-label">Дата приобретения</label>
<input type="date" class="form-control" name="date">
<input type="datetime-local" class="form-control" name="date">
</div>
<div class="col-sm-2 d-flex justify-content-evenly align-items-baseline">
<button type="submit" class="btn btn-primary mt-3 px-4">Сохранить</button>

View File

@ -95,7 +95,6 @@
var inwork = document.getElementById("inwork");
var ready = document.getElementById("ready");
var done = document.getElementById("done");
var order = 0;
for(var i = 1; i < table.rows.length; i++)
{
table.rows[i].onclick = function()
@ -108,7 +107,8 @@
index = this.rowIndex;
// add class selected to the row
this.classList.toggle("selected");
order = parseInt(this.cells[0].innerText);
var order = parseInt(this.cells[0].innerText)
remove.addEventListener("click", () => {
console.log('try to delete order')
$.ajax(
@ -117,7 +117,7 @@
type: 'POST',
data: { id: order }
}
)
).done(() => window.location.href='/Storekeeper/Orders')
})
inwork.addEventListener("click", () => {
console.log('try to delete order')
@ -127,7 +127,7 @@
type: 'POST',
data: { id : order, status : 1 }
}
)
).done(() => window.location.href='/Storekeeper/Orders')
})
ready.addEventListener("click", () => {
console.log('try to delete order')
@ -137,7 +137,7 @@
type: 'POST',
data: { id : order, status : 2 }
}
)
).done(() => window.location.href='/Storekeeper/Orders')
})
done.addEventListener("click", () => {
console.log('try to delete order')
@ -147,7 +147,7 @@
type: 'POST',
data: { id : order, status : 3 }
}
)
).done(() => window.location.href='/Storekeeper/Orders')
})
};
}

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -10,7 +10,7 @@ namespace HardwareShopDatabaseImplement
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseNpgsql("Host=localhost;Port=5432;Database=Computer_Hardware_Store4;Username=postgres;Password=1234");
optionsBuilder.UseNpgsql("Host=localhost;Port=5433;Database=Computer_Hardware_Store;Username=user;Password=12345");
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
}