Add project files.

This commit is contained in:
pkus
2025-01-24 13:37:01 +01:00
parent ee70a3c8af
commit ed726eea09
94 changed files with 4591 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
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))
.OrderByDescending(x => x.CreateDate).ToListAsync();
}
public async Task<CustomerOrderDto?> GetByOrderNumber(string orderNumber)
{
CustomerOrderDto? customerOrder = await context.CustomerOrders
.Where(x => x.CoNum == orderNumber)
.Select(x => mapper.Map<CustomerOrderDto>(x)).FirstOrDefaultAsync();
if (customerOrder == null) return null;
customerOrder.CustomerOrderLines = await context.CustomerOrderLines
.Where(x => x.CoNum == orderNumber)
.Select(x => mapper.Map<CustomerOrderLineDto>(x)).ToListAsync();
foreach (CustomerOrderLineDto customerOrderLine in customerOrder.CustomerOrderLines)
{
customerOrderLine.CustomerOrderLineItems = await context.CustomerOrderLineItems
.Where(x => x.CoNum == orderNumber && x.CoLine == customerOrderLine.CoLine)
.Select(x => mapper.Map<CustomerOrderLineItemDto>(x)).ToListAsync();
}
return customerOrder;
}
}
}