41 lines
1.6 KiB
C#
41 lines
1.6 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();
|
|
}
|
|
|
|
return customerOrder;
|
|
}
|
|
}
|
|
}
|