From 1484cfa45e88840fbddf2e9a572ed7ef10c0dbf5 Mon Sep 17 00:00:00 2001 From: ArifHilmi Date: Wed, 27 Nov 2024 10:34:32 +0800 Subject: [PATCH] add module & status --- Controllers/API/ModuleAPI.cs | 27 +++++++++++++ Views/Admin/CreateModule.cshtml | 2 + Views/Admin/ModuleAdmin.cshtml | 67 ++++++++++++++++++-------------- Views/Admin/ModuleSetting.cshtml | 15 ++++++- 4 files changed, 80 insertions(+), 31 deletions(-) diff --git a/Controllers/API/ModuleAPI.cs b/Controllers/API/ModuleAPI.cs index d18977a..bb48645 100644 --- a/Controllers/API/ModuleAPI.cs +++ b/Controllers/API/ModuleAPI.cs @@ -132,5 +132,32 @@ namespace PSTW_CentralSystem.Controllers.API return BadRequest(ex.Message); } } + + [HttpPost("DeleteModule")] + public async Task DeleteModule([FromBody] int? id) + { + try + { + var deleteList = await _authDbContext.ModuleSettings + .Where(x => x.SettingId == id) + .FirstOrDefaultAsync(); + + + if (deleteList != null) + { + _authDbContext.ModuleSettings.Remove(deleteList); + await _authDbContext.SaveChangesAsync(); + } + + var updatedList = await _authDbContext.ModuleSettings.ToListAsync(); + return Json(updatedList); + } + catch(Exception ex) + { + return BadRequest(ex.Message); + } + + } + } } diff --git a/Views/Admin/CreateModule.cshtml b/Views/Admin/CreateModule.cshtml index 2cccaa4..35131e7 100644 --- a/Views/Admin/CreateModule.cshtml +++ b/Views/Admin/CreateModule.cshtml @@ -130,7 +130,9 @@ if (!response.ok) { throw new Error('Name module already exists'); } + location.reload(); alert('Module information saved successfully'); + window.location.href = '/Admin/ModuleAdmin'; }) .catch(error => { console.error('There was a problem with the update operation:', error); diff --git a/Views/Admin/ModuleAdmin.cshtml b/Views/Admin/ModuleAdmin.cshtml index 91e6ff7..5afa14b 100644 --- a/Views/Admin/ModuleAdmin.cshtml +++ b/Views/Admin/ModuleAdmin.cshtml @@ -81,28 +81,28 @@ - - -