From de8b95eda162e51c5eb617e2e4cf9c52047fba3a Mon Sep 17 00:00:00 2001 From: ivanszabo Date: Fri, 4 Apr 2025 11:30:06 +0200 Subject: [PATCH] =?UTF-8?q?Alap=20t=C3=B6r=C3=A9ls=20Web=20Locations=20m?= =?UTF-8?q?=C5=B1k=C3=B6dik.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CheckPoints/CheckPointEditPage.cshtml | 30 +++++------ .../Locations/LocationEditPage.cshtml | 21 ++++++-- .../BaseStock/Locations/LocationsPage.cshtml | 51 +++++++++++-------- .../Locations/LocationsPage.cshtml.cs | 4 +- .../Services/BaseStockService.cs | 21 ++++++++ .../Services/Interfaces/IBaseStockService.cs | 4 +- 6 files changed, 87 insertions(+), 44 deletions(-) diff --git a/src/WorkFlowCheck.Web/Pages/BaseStock/CheckPoints/CheckPointEditPage.cshtml b/src/WorkFlowCheck.Web/Pages/BaseStock/CheckPoints/CheckPointEditPage.cshtml index 5ff9c8b..e14e545 100644 --- a/src/WorkFlowCheck.Web/Pages/BaseStock/CheckPoints/CheckPointEditPage.cshtml +++ b/src/WorkFlowCheck.Web/Pages/BaseStock/CheckPoints/CheckPointEditPage.cshtml @@ -146,21 +146,21 @@ data: JSON.stringify(formData.CheckPointDTO), success: function (response) { if (response.success) - { - showMessageModal({ - title: 'Figyelmem!', - message: 'Sikeres mentés.', - okText: 'Értettem' - }); - } - else - { - showMessageModal({ - title: 'Figyelmem, HIBA!', - message: 'Sikertelen mentés.', - okText: 'Értettem' - }); - } + { + showMessageModal({ + title: 'Figyelmem!', + message: 'Sikeres mentés.', + okText: 'Értettem' + }); + } + else + { + showMessageModal({ + title: 'Figyelmem, HIBA!', + message: 'Sikertelen mentés.', + okText: 'Értettem' + }); + } }, error: function (xhr, status, error) { // Hiba esetén diff --git a/src/WorkFlowCheck.Web/Pages/BaseStock/Locations/LocationEditPage.cshtml b/src/WorkFlowCheck.Web/Pages/BaseStock/Locations/LocationEditPage.cshtml index 7a92a9a..06d91cb 100644 --- a/src/WorkFlowCheck.Web/Pages/BaseStock/Locations/LocationEditPage.cshtml +++ b/src/WorkFlowCheck.Web/Pages/BaseStock/Locations/LocationEditPage.cshtml @@ -48,11 +48,22 @@ }, data: JSON.stringify(formData.LocationDTO), success: function (response) { - showMessageModal({ - title: 'Figyelmem!', - message: 'Sikeres mentés.', - okText: 'Értettem' - }); + if (response.success) + { + showMessageModal({ + title: 'Figyelmem!', + message: 'Sikeres mentés.', + okText: 'Értettem' + }); + } + else + { + showMessageModal({ + title: 'Figyelmem, HIBA!', + message: 'Sikertelen mentés.', + okText: 'Értettem' + }); + } }, error: function (xhr, status, error) { // Hiba esetén diff --git a/src/WorkFlowCheck.Web/Pages/BaseStock/Locations/LocationsPage.cshtml b/src/WorkFlowCheck.Web/Pages/BaseStock/Locations/LocationsPage.cshtml index 1f9e1e2..029d18c 100644 --- a/src/WorkFlowCheck.Web/Pages/BaseStock/Locations/LocationsPage.cshtml +++ b/src/WorkFlowCheck.Web/Pages/BaseStock/Locations/LocationsPage.cshtml @@ -74,26 +74,6 @@ $('#tbLocationsPage').on('click', '.delete-btn', function () { const row = table.row($(this).closest('tr')).data(); - - $.ajax({ - url: '/LocationsPage?handler=DeleteLocation', // A URL a handler-hez, ami az OnGetDeleteLocation metódust hívja - type: 'GET', // A kérés típusa, ebben az esetben GET - data: { id: 123 }, // Az id paraméter, amit átadsz - success: function (data) { - if (data.result) { - // A válaszban lévő result true, tehát sikeres volt a törlés - alert('Helyszín törölve!'); - } else { - alert('Hiba történt a törlés során.'); - } - }, - error: function (xhr, status, error) { - // Ha valami hiba történik a kérés során - alert('Hiba történt: ' + error); - } - }); - - showConfirmModal({ title: 'Törlés megerősítése', message: 'Biztosan törölni szeretnéd ezt az elemet?', @@ -101,7 +81,36 @@ cancelText: 'Mégsem' }).then(function(result) { if(result === 'ok') { - console.log('Törlés végrehajtva'); + $.ajax({ + url: '/BaseStock/Locations/LocationsPage?handler=DeleteLocation', + type: 'GET', + data: { id: row.id }, + success: function (data) { + console.log(data); + if (data) { + showMessageModal({ + title: 'Információ', + message: 'A törlés sikerült!', + okText: 'Értettem' + }); + + table.ajax.reload(); + } else { + showMessageModal({ + title: 'Hiba!', + message: 'A törlés NEM sikerült!', + okText: 'Értettem' + }); + } + }, + error: function (xhr, status, error) { + showMessageModal({ + title: 'Hiba!', + message: 'A törlés NEM sikerült!', + okText: 'Értettem' + }); + } + }); } }); }); diff --git a/src/WorkFlowCheck.Web/Pages/BaseStock/Locations/LocationsPage.cshtml.cs b/src/WorkFlowCheck.Web/Pages/BaseStock/Locations/LocationsPage.cshtml.cs index cf61d69..e2ed9ec 100644 --- a/src/WorkFlowCheck.Web/Pages/BaseStock/Locations/LocationsPage.cshtml.cs +++ b/src/WorkFlowCheck.Web/Pages/BaseStock/Locations/LocationsPage.cshtml.cs @@ -25,8 +25,8 @@ namespace WorkFlowCheck.Web.Pages.BaseStock.Locations } public async Task OnGetDeleteLocation(int id) { - - return new JsonResult(new { result = true }); + var isSuccess = await _baseStockService.DeleteLocation(id); + return new JsonResult(new { result = isSuccess }); } } } diff --git a/src/WorkFlowCheck.Web/Services/BaseStockService.cs b/src/WorkFlowCheck.Web/Services/BaseStockService.cs index 8a5ea91..fe45d97 100644 --- a/src/WorkFlowCheck.Web/Services/BaseStockService.cs +++ b/src/WorkFlowCheck.Web/Services/BaseStockService.cs @@ -144,6 +144,27 @@ namespace WorkFlowCheck.Web.Services return retVal; } + public async Task DeleteLocation(int id) + { + string endpoint = $"{_httpClient.BaseAddress}api/Sync/DeleteLocation/{id}"; + var retVal = false; + try + { + var response = await _httpClient.GetFromJsonAsync>(endpoint); + if (response != null) + { + if (response.IsSuccess) + { + return response.Data; + } + } + } + catch (Exception ex) + { + Log.Error(ex.Message); + } + return retVal; + } public async Task> UpdateCheckPoint(CheckPointDTO checkPointDTO) { diff --git a/src/WorkFlowCheck.Web/Services/Interfaces/IBaseStockService.cs b/src/WorkFlowCheck.Web/Services/Interfaces/IBaseStockService.cs index e3eaf07..a8c7c5d 100644 --- a/src/WorkFlowCheck.Web/Services/Interfaces/IBaseStockService.cs +++ b/src/WorkFlowCheck.Web/Services/Interfaces/IBaseStockService.cs @@ -5,8 +5,9 @@ namespace WorkFlowCheck.Web.Services.Interfaces { public interface IBaseStockService { - + Task GetCheckPoint(int id); + //Task DeleteCheckpoint(int id); Task> GetAllCheckPoints(); Task> UpdateCheckPoint(CheckPointDTO checkPointDTO); @@ -16,6 +17,7 @@ namespace WorkFlowCheck.Web.Services.Interfaces Task> UpdateEquipment(EquipmentDTO equipmentDTO); Task GetLocation(int id); + Task DeleteLocation(int id); Task> GetAllLocations(); Task> UpdateLocation(LocationDTO LocationDTO);