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 @@ - - -