order fix
This commit is contained in:
@@ -163,20 +163,22 @@ namespace Webshop.Application.Services.Customers
|
|||||||
var customer = await _customerRepository.GetByUserIdAsync(userId);
|
var customer = await _customerRepository.GetByUserIdAsync(userId);
|
||||||
if (customer == null)
|
if (customer == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null; // Kein Kunde, kann keine Bestellung abrufen
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Finde die Bestellung und stelle sicher, dass sie zum eingeloggten Kunden gehört
|
||||||
var order = await _context.Orders
|
var order = await _context.Orders
|
||||||
.Include(o => o.BillingAddress)
|
.Include(o => o.BillingAddress)
|
||||||
.Include(o => o.ShippingAddress)
|
.Include(o => o.ShippingAddress)
|
||||||
.Include(o => o.PaymentMethodInfo)
|
.Include(o => o.PaymentMethodInfo) // << HINZUFÜGEN, um PaymentMethodInfo zu laden >>
|
||||||
|
.Include(o => o.ShippingMethodInfo) // << HINZUFÜGEN, um ShippingMethodInfo zu laden >>
|
||||||
.Include(o => o.OrderItems)
|
.Include(o => o.OrderItems)
|
||||||
.ThenInclude(oi => oi.Product)
|
.ThenInclude(oi => oi.Product) // Optional: Dann das Produkt laden
|
||||||
.FirstOrDefaultAsync(o => o.Id == orderId && o.CustomerId == customer.Id);
|
.FirstOrDefaultAsync(o => o.Id == orderId && o.CustomerId == customer.Id);
|
||||||
|
|
||||||
if (order == null)
|
if (order == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null; // Bestellung nicht gefunden oder gehört nicht diesem Kunden
|
||||||
}
|
}
|
||||||
|
|
||||||
return new OrderDetailDto
|
return new OrderDetailDto
|
||||||
@@ -187,9 +189,9 @@ namespace Webshop.Application.Services.Customers
|
|||||||
CustomerId = order.CustomerId,
|
CustomerId = order.CustomerId,
|
||||||
Status = Enum.TryParse<OrderStatus>(order.OrderStatus, true, out var orderStatus) ? orderStatus : OrderStatus.Pending,
|
Status = Enum.TryParse<OrderStatus>(order.OrderStatus, true, out var orderStatus) ? orderStatus : OrderStatus.Pending,
|
||||||
TotalAmount = order.OrderTotal,
|
TotalAmount = order.OrderTotal,
|
||||||
ShippingAddress = order.ShippingAddress,
|
ShippingAddress = order.ShippingAddress, // Annahme: Address DTO Mapping
|
||||||
BillingAddress = order.BillingAddress,
|
BillingAddress = order.BillingAddress, // Annahme: Address DTO Mapping
|
||||||
PaymentMethod = order.PaymentMethod,
|
PaymentMethod = order.PaymentMethod, // << KORREKTUR: Dies ist ein String in Ihrer Entität >>
|
||||||
PaymentStatus = Enum.TryParse<PaymentStatus>(order.PaymentStatus, true, out var paymentStatus) ? paymentStatus : PaymentStatus.Pending,
|
PaymentStatus = Enum.TryParse<PaymentStatus>(order.PaymentStatus, true, out var paymentStatus) ? paymentStatus : PaymentStatus.Pending,
|
||||||
ShippingTrackingNumber = order.ShippingTrackingNumber,
|
ShippingTrackingNumber = order.ShippingTrackingNumber,
|
||||||
ShippedDate = order.ShippedDate,
|
ShippedDate = order.ShippedDate,
|
||||||
|
|||||||
Reference in New Issue
Block a user