Files
FA_WEB/SytelineSaAppEfDataModel/Services/CustomerOrderService.cs
Piotr Kus 177fce1fdf * Added DocType to Edi and CO
* Moved SOGrid to Shared and reuse in CO view
* Added retrieving of COTranslates to CO
2025-02-03 19:41:35 +01:00

47 lines
2.0 KiB
C#

using AutoMapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using SytelineSaAppEfDataModel.Dtos;
namespace SytelineSaAppEfDataModel.Services
{
public class CustomerOrderService(SytelineSaAppDbContext context, IMapper mapper) : ICustomerOrderService
{
public async Task<IEnumerable<CustomerOrderDto>> GetAll()
{
return await context.CustomerOrders.Select(x => mapper.Map<CustomerOrderDto>(x)).ToListAsync();
}
public async Task<CustomerOrderDto?> GetByOrderNumber(Guid orderNumber)
{
CustomerOrderDto? customerOrder = await context.CustomerOrders
.Where(x => x.RowPointer == orderNumber)
.Select(x => mapper.Map<CustomerOrderDto>(x)).FirstOrDefaultAsync();
if (customerOrder == null) return null;
customerOrder.CustomerOrderLines = await context.CustomerOrderLines
.Where(x => x.CoNum == customerOrder.CoNum)
.Select(x => mapper.Map<CustomerOrderLineDto>(x)).ToListAsync();
foreach (CustomerOrderLineDto customerOrderLine in customerOrder.CustomerOrderLines)
{
customerOrderLine.CustomerOrderLineItems = await context.CustomerOrderLineItems
.Where(x => x.CoNum == customerOrder.CoNum && x.CoLine == customerOrderLine.CoLine)
.Select(x => mapper.Map<CustomerOrderLineItemDto>(x)).ToListAsync();
}
IList<EdiCustomerOrderTranslateDto> ediCustomerOrderTranslates = await context.EdiCustomerOrderTranslates
.Where(x => x.CoCoNum == customerOrder.CoNum)
.Select(x => mapper.Map<EdiCustomerOrderTranslateDto>(x)).ToListAsync();
customerOrder.EdiCustomerOrderTranslates = ediCustomerOrderTranslates;
return customerOrder;
}
}
}