Add project files.
This commit is contained in:
41
SytelineSaAppEfDataModel/Services/CustomerOrderService.cs
Normal file
41
SytelineSaAppEfDataModel/Services/CustomerOrderService.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user