Files
FA_WEB/FaKrosnoApi/Controllers/WzHeaderController.cs
Piotr Kus f58d2ab04c * Further improvements of Warehouse view
* Fixed issue with not saving Products updates
2025-05-24 21:47:32 +02:00

55 lines
1.9 KiB
C#

using Microsoft.AspNetCore.Mvc;
using SytelineSaAppEfDataModel.Dtos;
using SytelineSaAppEfDataModel.Services;
namespace FaKrosnoApi.Controllers;
[ApiController]
[Route("api/[controller]")]
public class WzHeaderController(IWzHeaderService service, IMaterialTransactionService materialTransactionService) : Controller
{
[HttpGet]
public async Task<ActionResult<IEnumerable<WzHeaderDto>>> GetAll()
{
IEnumerable<WzHeaderDto> wzHeaders = await service.GetAll();
return Ok(wzHeaders);
}
[HttpGet("by-customer-number")]
public async Task<ActionResult<IEnumerable<MaterialTransactionDto>>> GetByCustomerNumber(
[FromQuery] string customerNumber, [FromQuery] int customerSequence)
{
IEnumerable<MaterialTransactionDto> materialTransactions =
await materialTransactionService.GetByCustomerNumber(customerNumber, customerSequence);
return Ok(materialTransactions);
}
[HttpGet("all-wz-headers")]
public async Task<ActionResult<IEnumerable<MaterialTransactionDto>>> GetHeadersByCustomerNumber(
[FromQuery] string customerNumber, [FromQuery] int customerSequence)
{
IEnumerable<WzHeaderDto> wzHeaders =
await service.GetByCustomerNumber(customerNumber, customerSequence);
return Ok(wzHeaders.OrderByDescending(x => x.CreatedDate));
}
[HttpPost]
public async Task<ActionResult> CreateHeader([FromBody] WzHeaderDto wzHeader)
{
if (wzHeader == null)
{
return BadRequest("WzHeader cannot be null.");
}
await service.CreateHeader(wzHeader);
return CreatedAtAction(nameof(CreateHeader), wzHeader);
}
[HttpGet("by-id")]
public async Task<ActionResult<WzHeaderDto>> GetById([FromQuery] Guid id)
{
WzHeaderDto? wzHeader = await service.GetById(id);
return wzHeader != null ? Ok(wzHeader) : NotFound();
}
}