update
This commit is contained in:
parent
09fa8fc604
commit
b378c73152
@ -99,24 +99,29 @@ namespace PSTW_CentralSystem.Controllers.API
|
||||
return Json(qcList);
|
||||
}
|
||||
|
||||
[HttpPost("addData")]
|
||||
public async Task<IActionResult> addData([FromBody] ModuleSettingModel modelSettingList)
|
||||
[HttpPost("AddModule")]
|
||||
public async Task<IActionResult> AddModule([FromBody] ModuleSettingModel module)
|
||||
{
|
||||
var existingModule = await _authDbContext.ModuleSettings.Where(x => x.ModuleName.ToLower() == modelSettingList.ModuleName.ToLower()).FirstOrDefaultAsync();
|
||||
|
||||
if (existingModule != null)
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest("Module name already exists."); // Return a 400 Bad Request
|
||||
return BadRequest(ModelState);
|
||||
}
|
||||
if (module == null)
|
||||
{
|
||||
return NotFound("Module is null");
|
||||
}
|
||||
|
||||
// Add new module
|
||||
modelSettingList.ModuleStatus = 1; // Default status
|
||||
|
||||
_authDbContext.ModuleSettings.Add(modelSettingList);
|
||||
try
|
||||
{
|
||||
_authDbContext.ModuleSettings.Add(module);
|
||||
await _authDbContext.SaveChangesAsync();
|
||||
|
||||
|
||||
return Json(modelSettingList);
|
||||
var updatedList = await _authDbContext.ModuleSettings.ToListAsync();
|
||||
return Json(updatedList);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user