101 lines
4.3 KiB
C#
101 lines
4.3 KiB
C#
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using SytelineSaAppEfDataModel.Dtos;
|
|
using SytelineSaAppEfDataModel.Services;
|
|
|
|
namespace FaKrosnoApi.Controllers
|
|
{
|
|
[ApiController]
|
|
[Route("api/[controller]")]
|
|
public class CustomerOrdersController(ICustomerOrderService service) : Controller
|
|
{
|
|
[HttpGet]
|
|
public async Task<ActionResult<IEnumerable<CustomerOrderDto>>> GetAll()
|
|
{
|
|
IEnumerable<CustomerOrderDto?> customerOrders = await service.GetAll();
|
|
return Ok(customerOrders);
|
|
}
|
|
|
|
[HttpGet("by-order-number")]
|
|
public async Task<ActionResult<CustomerOrderDto?>> GetByCustomerOrderNumber(
|
|
[FromQuery] Guid customerOrderNumber)
|
|
{
|
|
CustomerOrderDto? customerOrder = await service.GetByOrderNumber(customerOrderNumber);
|
|
return customerOrder != null ? Ok(customerOrder) : NotFound();
|
|
}
|
|
|
|
[HttpGet("by-co-number")]
|
|
public async Task<ActionResult<CustomerOrderDto?>> GetByCoNumber([FromQuery] string customerOrderNumber)
|
|
{
|
|
CustomerOrderDto? customerOrder = await service.GetByCoNumber(customerOrderNumber);
|
|
return customerOrder != null ? Ok(customerOrder) : NotFound();
|
|
}
|
|
|
|
[HttpGet("lines-by-co-number")]
|
|
public async Task<ActionResult<IEnumerable<CustomerOrderLineDto>?>> GetLinesByCoNumber(
|
|
[FromQuery] string customerOrderNumber)
|
|
{
|
|
var customerOrderLines = await service.GetLinesByCoNumber(customerOrderNumber);
|
|
return customerOrderLines != null ? Ok(customerOrderLines) : NotFound();
|
|
}
|
|
|
|
[HttpGet("items-by-co-number")]
|
|
public async Task<ActionResult<IEnumerable<CustomerOrderLineItemDto>?>> GetItemsByCoNumber(
|
|
[FromQuery] string customerOrderNumber)
|
|
{
|
|
var customerOrderLineItems = await service.GetItemsByCoNumber(customerOrderNumber);
|
|
return customerOrderLineItems != null ? Ok(customerOrderLineItems) : NotFound();
|
|
}
|
|
|
|
[HttpGet("by-customer-and-po")]
|
|
public async Task<ActionResult<CustomerOrderDto?>> GetByCustomerAndPo([FromQuery] string customerNumber,
|
|
[FromQuery] int customerSequence, [FromQuery] string poNumber)
|
|
{
|
|
CustomerOrderDto? customerOrder =
|
|
await service.GetByCustomerAndPo(customerNumber, customerSequence, poNumber);
|
|
return customerOrder != null ? Ok(customerOrder) : NotFound();
|
|
}
|
|
|
|
[HttpGet("list-by-customer-and-po")]
|
|
public async Task<ActionResult<IList<CustomerOrderDto?>>> GetListByCustomerAndPo(
|
|
[FromQuery] string customerNumber, [FromQuery] int customerSequence, [FromQuery] string poNumber)
|
|
{
|
|
IList<CustomerOrderDto> customerOrders =
|
|
await service.GetListByCustomerAndPo(customerNumber, customerSequence, poNumber);
|
|
|
|
foreach (CustomerOrderDto customerOrder in customerOrders)
|
|
{
|
|
customerOrder.CustomerOrderLines = await service.GetLinesByCoNumber(customerOrder.CoNum) ?? [];
|
|
|
|
foreach (CustomerOrderLineDto customerOrderLine in customerOrder.CustomerOrderLines)
|
|
{
|
|
customerOrderLine.CustomerOrderLineItems =
|
|
await service.GetItemsByCoNumber(customerOrder.CoNum) ?? [];
|
|
}
|
|
}
|
|
|
|
return Ok(customerOrders);
|
|
}
|
|
|
|
[HttpGet("list-by-customer")]
|
|
public async Task<ActionResult<IList<CustomerOrderDto?>>> GetListByCustomer([FromQuery] string customerNumber,
|
|
[FromQuery] int customerSequence)
|
|
{
|
|
IList<CustomerOrderDto> customerOrders = await service.GetListByCustomer(customerNumber, customerSequence);
|
|
|
|
foreach (CustomerOrderDto customerOrder in customerOrders)
|
|
{
|
|
customerOrder.CustomerOrderLines = await service.GetLinesByCoNumber(customerOrder.CoNum) ?? [];
|
|
|
|
foreach (CustomerOrderLineDto customerOrderLine in customerOrder.CustomerOrderLines)
|
|
{
|
|
customerOrderLine.CustomerOrderLineItems =
|
|
await service.GetItemsByCoNumber(customerOrder.CoNum) ?? [];
|
|
}
|
|
}
|
|
|
|
return Ok(customerOrders);
|
|
}
|
|
}
|
|
}
|