add module & status
This commit is contained in:
parent
f9666d341c
commit
1484cfa45e
@ -132,5 +132,32 @@ namespace PSTW_CentralSystem.Controllers.API
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost("DeleteModule")]
|
||||
public async Task<IActionResult> 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -81,9 +81,8 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- MODAL -->
|
||||
<div class="modal fade" id="confirm-dialog" tabindex="-1" role="dialog" aria-labelledby="confirm-dialog-title" aria-hidden="true">
|
||||
<!-- MODAL -->
|
||||
<div class="modal fade" id="confirm-dialog" v-show="selectedModule">
|
||||
<div class="modal-dialog modal-dialog-centered" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
@ -99,12 +98,13 @@
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
|
||||
<input type="hidden" id="delete-id">
|
||||
<a id="confirmButton" href="#" class="btn btn-danger" v-on:click="confirmDelete(selectedModule)">Confirm</a>
|
||||
<a id="confirmButton" class="btn btn-danger" v-on:click="confirmDelete(selectedModule)">Confirm</a>
|
||||
</div>
|
||||
</div>
|
||||
<div v-else><p>Loading...</p></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@section Scripts {
|
||||
@{
|
||||
@ -147,24 +147,31 @@
|
||||
}
|
||||
},
|
||||
deleteModule(module) {
|
||||
this.selectedModule = module; // Set selected user
|
||||
$('#confirm-dialog').modal('show'); // Show the modal
|
||||
this.selectedModule = module;
|
||||
$('#confirm-dialog').modal('show');
|
||||
},
|
||||
confirmDelete(module) {
|
||||
fetch('/ModuleAPI/DeleteModule/' + module.settingId, {
|
||||
method: 'POST'
|
||||
if (!module || !module.settingId) {
|
||||
console.error('Invalid module data');
|
||||
return;
|
||||
}
|
||||
|
||||
$('#confirm-dialog').modal('hide');
|
||||
|
||||
fetch('/ModuleAPI/DeleteModule', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(module.settingId)
|
||||
})
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to delete module');
|
||||
}
|
||||
// Remove the deleted user from the userData array
|
||||
const index = this.moduleData.findIndex(u => u.settingId === module.settingId);
|
||||
if (index !== -1) {
|
||||
|
||||
alert("Module deleted successfully");
|
||||
this.moduleData.splice(index, 1);
|
||||
}
|
||||
$('#confirm-dialog').modal('hide'); // Hide the modal after deletion
|
||||
location.reload();
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Failed to delete module with status:', error);
|
||||
|
||||
@ -81,6 +81,17 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<label class="col-md-3 mt-3">Module Status</label>
|
||||
<div class="col-md-6">
|
||||
<select class="form-select shadow-none mt-3" name="moduleStatus" v-model="moduleData.moduleStatus" style="height: 36px; width: 100%">
|
||||
<optgroup label="General">
|
||||
<option value="1">Enabled</option>
|
||||
<option value="0">Disabled</option>
|
||||
</optgroup>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="border-top">
|
||||
<div class="card-body" v-on:click="saveData">
|
||||
@ -248,7 +259,8 @@
|
||||
.then(data => {
|
||||
console.log('Method added successfully:', data);
|
||||
alert('Method added successfully');
|
||||
this.fetchXModule(); // Refresh the module data
|
||||
location.reload();
|
||||
this.fetchXModule();
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('There was a problem when adding the module operation:', error);
|
||||
@ -268,6 +280,7 @@
|
||||
throw new Error('Failed to save module information');
|
||||
}
|
||||
alert('Module information saved successfully');
|
||||
location.reload();
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('There was a problem with the update operation:', error);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user