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);
|
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) {
|
if (!response.ok) {
|
||||||
throw new Error('Name module already exists');
|
throw new Error('Name module already exists');
|
||||||
}
|
}
|
||||||
|
location.reload();
|
||||||
alert('Module information saved successfully');
|
alert('Module information saved successfully');
|
||||||
|
window.location.href = '/Admin/ModuleAdmin';
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.error('There was a problem with the update operation:', error);
|
console.error('There was a problem with the update operation:', error);
|
||||||
|
|||||||
@ -81,9 +81,8 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<!-- MODAL -->
|
||||||
<!-- MODAL -->
|
<div class="modal fade" id="confirm-dialog" v-show="selectedModule">
|
||||||
<div class="modal fade" id="confirm-dialog" tabindex="-1" role="dialog" aria-labelledby="confirm-dialog-title" aria-hidden="true">
|
|
||||||
<div class="modal-dialog modal-dialog-centered" role="document">
|
<div class="modal-dialog modal-dialog-centered" role="document">
|
||||||
<div class="modal-content">
|
<div class="modal-content">
|
||||||
<div class="modal-header">
|
<div class="modal-header">
|
||||||
@ -99,12 +98,13 @@
|
|||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
|
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
|
||||||
<input type="hidden" id="delete-id">
|
<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>
|
</div>
|
||||||
<div v-else><p>Loading...</p></div>
|
<div v-else><p>Loading...</p></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@section Scripts {
|
@section Scripts {
|
||||||
@{
|
@{
|
||||||
@ -147,24 +147,31 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
deleteModule(module) {
|
deleteModule(module) {
|
||||||
this.selectedModule = module; // Set selected user
|
this.selectedModule = module;
|
||||||
$('#confirm-dialog').modal('show'); // Show the modal
|
$('#confirm-dialog').modal('show');
|
||||||
},
|
},
|
||||||
confirmDelete(module) {
|
confirmDelete(module) {
|
||||||
fetch('/ModuleAPI/DeleteModule/' + module.settingId, {
|
if (!module || !module.settingId) {
|
||||||
method: 'POST'
|
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 => {
|
.then(response => {
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error('Failed to delete module');
|
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");
|
alert("Module deleted successfully");
|
||||||
this.moduleData.splice(index, 1);
|
location.reload();
|
||||||
}
|
|
||||||
$('#confirm-dialog').modal('hide'); // Hide the modal after deletion
|
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.error('Failed to delete module with status:', error);
|
console.error('Failed to delete module with status:', error);
|
||||||
|
|||||||
@ -81,6 +81,17 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</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>
|
||||||
<div class="border-top">
|
<div class="border-top">
|
||||||
<div class="card-body" v-on:click="saveData">
|
<div class="card-body" v-on:click="saveData">
|
||||||
@ -248,7 +259,8 @@
|
|||||||
.then(data => {
|
.then(data => {
|
||||||
console.log('Method added successfully:', data);
|
console.log('Method added successfully:', data);
|
||||||
alert('Method added successfully');
|
alert('Method added successfully');
|
||||||
this.fetchXModule(); // Refresh the module data
|
location.reload();
|
||||||
|
this.fetchXModule();
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.error('There was a problem when adding the module operation:', 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');
|
throw new Error('Failed to save module information');
|
||||||
}
|
}
|
||||||
alert('Module information saved successfully');
|
alert('Module information saved successfully');
|
||||||
|
location.reload();
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.error('There was a problem with the update operation:', error);
|
console.error('There was a problem with the update operation:', error);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user