63 lines
1.9 KiB
C#
63 lines
1.9 KiB
C#
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<InvMainAPI> _logger;
|
|
private readonly AuthDBContext _authDbContext;
|
|
|
|
public InvMainAPI(ILogger<InvMainAPI> logger, AuthDBContext authDbContext)
|
|
{
|
|
_logger = logger;
|
|
_authDbContext = authDbContext;
|
|
}
|
|
|
|
[HttpPost("ManufacturerList")]
|
|
public async Task<IActionResult> ManufacturerList()
|
|
{
|
|
var manifacturerList = await _authDbContext.Manufacturers.ToListAsync();
|
|
return Json(manifacturerList);
|
|
}
|
|
[HttpPost("AddManufacturer")]
|
|
public async Task<IActionResult> 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);
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|