order service überarbeitet
This commit is contained in:
@@ -30,13 +30,15 @@ namespace Webshop.Application.Services.Customers
|
||||
var customer = await _customerRepository.GetByUserIdAsync(userId);
|
||||
if (customer == null)
|
||||
{
|
||||
// A valid user might not have a customer profile yet. Return empty list.
|
||||
return ServiceResult.Ok<IEnumerable<OrderSummaryDto>>(new List<OrderSummaryDto>());
|
||||
}
|
||||
|
||||
var orders = await _context.Orders
|
||||
.Where(o => o.CustomerId == customer.Id)
|
||||
.OrderByDescending(o => o.OrderDate)
|
||||
// +++ KORREKTUR: Verkn<6B>pfte Entit<69>ten explizit laden +++
|
||||
.Include(o => o.ShippingMethodInfo)
|
||||
.Include(o => o.PaymentMethodInfo)
|
||||
.ToListAsync();
|
||||
|
||||
var dtos = orders.Select(o => new OrderSummaryDto
|
||||
@@ -47,7 +49,10 @@ namespace Webshop.Application.Services.Customers
|
||||
CustomerName = $"{customer.FirstName} {customer.LastName}",
|
||||
TotalAmount = o.OrderTotal,
|
||||
Status = Enum.TryParse<OrderStatus>(o.OrderStatus, true, out var os) ? os : OrderStatus.Pending,
|
||||
PaymentStatus = Enum.TryParse<PaymentStatus>(o.PaymentStatus, true, out var ps) ? ps : PaymentStatus.Pending
|
||||
PaymentStatus = Enum.TryParse<PaymentStatus>(o.PaymentStatus, true, out var ps) ? ps : PaymentStatus.Pending,
|
||||
// +++ KORREKTUR: Daten aus den geladenen Entit<69>ten zuweisen +++
|
||||
ShippingMethodName = o.ShippingMethodInfo?.Name,
|
||||
PaymentMethodName = o.PaymentMethodInfo?.Name
|
||||
}).ToList();
|
||||
|
||||
return ServiceResult.Ok<IEnumerable<OrderSummaryDto>>(dtos);
|
||||
@@ -65,6 +70,9 @@ namespace Webshop.Application.Services.Customers
|
||||
.Include(o => o.BillingAddress)
|
||||
.Include(o => o.ShippingAddress)
|
||||
.Include(o => o.OrderItems)
|
||||
// +++ KORREKTUR: Verkn<6B>pfte Entit<69>ten explizit laden +++
|
||||
.Include(o => o.ShippingMethodInfo)
|
||||
.Include(o => o.PaymentMethodInfo)
|
||||
.FirstOrDefaultAsync(o => o.Id == orderId);
|
||||
|
||||
if (order == null)
|
||||
@@ -82,6 +90,8 @@ namespace Webshop.Application.Services.Customers
|
||||
|
||||
private OrderDetailDto MapToOrderDetailDto(Order order)
|
||||
{
|
||||
// Die `MapToDto`-Methode muss die neuen Daten ebenfalls verwenden.
|
||||
// Die `PaymentMethod`-Eigenschaft in `OrderDetailDto` scheint den Namen zu erwarten.
|
||||
return new OrderDetailDto
|
||||
{
|
||||
Id = order.Id,
|
||||
@@ -98,7 +108,9 @@ namespace Webshop.Application.Services.Customers
|
||||
City = order.ShippingAddress.City,
|
||||
PostalCode = order.ShippingAddress.PostalCode,
|
||||
Country = order.ShippingAddress.Country,
|
||||
Type = order.ShippingAddress.Type
|
||||
Type = order.ShippingAddress.Type,
|
||||
FirstName = order.ShippingAddress.FirstName,
|
||||
LastName = order.ShippingAddress.LastName
|
||||
},
|
||||
BillingAddress = new AddressDto
|
||||
{
|
||||
@@ -108,9 +120,12 @@ namespace Webshop.Application.Services.Customers
|
||||
City = order.BillingAddress.City,
|
||||
PostalCode = order.BillingAddress.PostalCode,
|
||||
Country = order.BillingAddress.Country,
|
||||
Type = order.BillingAddress.Type
|
||||
Type = order.BillingAddress.Type,
|
||||
FirstName = order.BillingAddress.FirstName,
|
||||
LastName = order.BillingAddress.LastName
|
||||
},
|
||||
PaymentMethod = order.PaymentMethod,
|
||||
// +++ KORREKTUR: Den Namen aus der geladenen Entit<69>t verwenden +++
|
||||
PaymentMethod = order.PaymentMethodInfo?.Name,
|
||||
PaymentStatus = Enum.TryParse<PaymentStatus>(order.PaymentStatus, true, out var ps) ? ps : PaymentStatus.Pending,
|
||||
ShippingTrackingNumber = order.ShippingTrackingNumber,
|
||||
ShippedDate = order.ShippedDate,
|
||||
|
||||
Reference in New Issue
Block a user