using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using PSTW_CentralSystem.Areas.Inventory.Models; using PSTW_CentralSystem.DBContext; using PSTW_CentralSystem.Models; namespace PSTW_CentralSystem.Controllers.API { [ApiController] [Route("[controller]")] public class ModuleAPI : Controller { private readonly ILogger _logger; private readonly AuthDBContext _authDbContext; public ModuleAPI(ILogger logger, AuthDBContext authDbContext) { _logger = logger; _authDbContext = authDbContext; } [HttpPost("GetModuleInformation")] public async Task GetModuleInformation() { var qcList = await _authDbContext.ModuleSettings.ToListAsync(); return Json(qcList); } [HttpPost("GetXModuleInformation")] public async Task GetXModuleInformation(int? id) { var qcList = await _authDbContext.ModuleSettings.Where(x => x.SettingId == id).FirstOrDefaultAsync(); return Json(qcList); } [HttpPost("AddModule")] public async Task AddModule([FromBody] ModuleSettingModel module) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (module == null) { return NotFound("Module is null"); } try { _authDbContext.ModuleSettings.Add(module); await _authDbContext.SaveChangesAsync(); var updatedList = await _authDbContext.ModuleSettings.ToListAsync(); return Json(updatedList); } catch (Exception ex) { return BadRequest(ex.Message); } } } }