using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Mono.TextTemplating; using PSTW_CentralSystem.Areas.Inventory.Models; using PSTW_CentralSystem.DBContext; using PSTW_CentralSystem.Models; using System.Diagnostics; using System.Reflection; namespace PSTW_CentralSystem.Controllers.API.Inventory { [ApiController] [Route("[controller]")] public class InvMainAPI : Controller { private readonly ILogger _logger; private readonly AuthDBContext _authDbContext; public InvMainAPI(ILogger logger, AuthDBContext authDbContext) { _logger = logger; _authDbContext = authDbContext; } [HttpPost("ManufacturerList")] public async Task ManufacturerList() { var manifacturerList = await _authDbContext.Manufacturers.ToListAsync(); return Json(manifacturerList); } [HttpPost("AddManufacturer")] public async Task AddManufacturer([FromBody] ManufacturerModel manufacturer) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (manufacturer == null) { return BadRequest("Manufacturer is null"); } try { _authDbContext.Manufacturers.Add(new ManufacturerModel { ManufacturerName = manufacturer.ManufacturerName, }); await _authDbContext.SaveChangesAsync(); var updatedList = await _authDbContext.Manufacturers.ToListAsync(); return Json(updatedList); } catch (Exception ex) { return BadRequest(ex.Message); } } } }