добавлена смена статуса у покупки

This commit is contained in:
Николай 2023-05-16 18:35:08 +04:00
parent 8cc02e4532
commit f032fc0f44
3 changed files with 35 additions and 37 deletions

View File

@ -76,7 +76,7 @@ namespace HardwareShopRestApi.Controllers
{ {
try try
{ {
_purchaseLogic.Update(model); _purchaseLogic.DeliveryPurchase(model);
} }
catch (Exception ex) catch (Exception ex)
{ {

View File

@ -324,6 +324,28 @@ namespace HardwareShopWorkerApp.Controllers
APIClient.PostRequest("api/purchase/createpurchase", purchaseModel); APIClient.PostRequest("api/purchase/createpurchase", purchaseModel);
} }
[HttpPost]
public void UpdatePurchase(int id, int status)
{
if (APIClient.User == null)
{
throw new Exception("Вы как сюда попали? Сюда вход только авторизованным");
}
if (id <= 0)
{
throw new Exception("Некорректный идентификатор");
}
if (status <= 0)
{
throw new Exception("Некорректный статус");
}
APIClient.PostRequest("api/purchase/updatepurchase", new PurchaseBindingModel
{
Id = id,
PurchaseStatus = (PurchaseStatus)status
});
}
[HttpGet] [HttpGet]
public IActionResult WorkerReport() public IActionResult WorkerReport()
{ {

View File

@ -18,13 +18,11 @@
<p> <p>
<a asp-controller="Home" asp-action="CreatePurchase" class="btn btn-primary mx-2">Добавить</a> <a asp-controller="Home" asp-action="CreatePurchase" class="btn btn-primary mx-2">Добавить</a>
<button type="button" class="btn btn-primary mx-2" id="delete">Удалить заказ</button> <button type="button" class="btn btn-primary mx-2" id="delete">Удалить заказ</button>
<button type="button" class="btn btn-primary mx-2" id="inwork">Выполняется</button>
<button type="button" class="btn btn-primary mx-2" id="ready">Готов</button>
<button type="button" class="btn btn-primary mx-2" id="done">Выдан</button> <button type="button" class="btn btn-primary mx-2" id="done">Выдан</button>
</p> </p>
</div> </div>
<div class="text-center" name="id"> <div class="text-center">
<table class="table"> <table class="table" id="table">
<thead> <thead>
<tr> <tr>
<th> <th>
@ -100,10 +98,8 @@
var table = document.getElementById("table"); var table = document.getElementById("table");
var remove = document.getElementById("delete"); var remove = document.getElementById("delete");
var inwork = document.getElementById("inwork");
var ready = document.getElementById("ready");
var done = document.getElementById("done"); var done = document.getElementById("done");
var order = 0; var purchase = 0;
for (var i = 1; i < table.rows.length; i++) { for (var i = 1; i < table.rows.length; i++) {
table.rows[i].onclick = function () { table.rows[i].onclick = function () {
// remove the background from the previous selected row // remove the background from the previous selected row
@ -114,46 +110,26 @@
index = this.rowIndex; index = this.rowIndex;
// add class selected to the row // add class selected to the row
this.classList.toggle("selected"); this.classList.toggle("selected");
order = parseInt(this.cells[0].innerText); purchase = parseInt(this.cells[0].innerText);
remove.addEventListener("click", () => { remove.addEventListener("click", () => {
console.log('try to delete order') console.log('try to delete purchase')
$.ajax( $.ajax(
{ {
url: `/Storekeeper/DeleteOrder`, url: `/Home/DeletePurchase`,
type: 'POST', type: 'POST',
data: { id: order } data: { id: purchase }
} }
) ).done(() => window.location.href = '/Home/Purchase')
})
inwork.addEventListener("click", () => {
console.log('try to delete order')
$.ajax(
{
url: `/Storekeeper/UpdateOrder`,
type: 'POST',
data: { id: order, status: 1 }
}
)
})
ready.addEventListener("click", () => {
console.log('try to delete order')
$.ajax(
{
url: `/Storekeeper/UpdateOrder`,
type: 'POST',
data: { id: order, status: 2 }
}
)
}) })
done.addEventListener("click", () => { done.addEventListener("click", () => {
console.log('try to delete order') console.log('try to delete purchase')
$.ajax( $.ajax(
{ {
url: `/Storekeeper/UpdateOrder`, url: `/Home/UpdatePurchase`,
type: 'POST', type: 'POST',
data: { id: order, status: 3 } data: { id: purchase, status: 1 }
} }
) ).done(() => window.location.href = '/Home/Purchases')
}) })
}; };
} }