diff --git a/Webshop.Application/DTOs/Customers/AddressDto.cs b/Webshop.Application/DTOs/Customers/AddressDto.cs index 449c334..a1db3c5 100644 --- a/Webshop.Application/DTOs/Customers/AddressDto.cs +++ b/Webshop.Application/DTOs/Customers/AddressDto.cs @@ -1,9 +1,6 @@ -// Auto-generiert von CreateWebshopFiles.ps1 +// src/Webshop.Application/DTOs/Customers/AddressDto.cs using System; -using System.Collections.Generic; -using System.Threading.Tasks; - - +using Webshop.Domain.Enums; namespace Webshop.Application.DTOs.Customers { @@ -16,5 +13,9 @@ namespace Webshop.Application.DTOs.Customers public string PostalCode { get; set; } = string.Empty; public string Country { get; set; } = string.Empty; public AddressType Type { get; set; } + + // Fügen Sie auch FirstName und LastName hinzu, falls diese in der Adresse gespeichert sind + public string FirstName { get; set; } = string.Empty; + public string LastName { get; set; } = string.Empty; } -} +} \ No newline at end of file diff --git a/Webshop.Application/DTOs/Orders/OrderDetailDto.cs b/Webshop.Application/DTOs/Orders/OrderDetailDto.cs index 4e3bb9d..4e275ac 100644 --- a/Webshop.Application/DTOs/Orders/OrderDetailDto.cs +++ b/Webshop.Application/DTOs/Orders/OrderDetailDto.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; +using Webshop.Application.DTOs.Customers; using Webshop.Domain.Entities; @@ -24,8 +25,9 @@ namespace Webshop.Application.DTOs.Orders public DateTimeOffset? DeliveredDate { get; set; } public PaymentStatus PaymentStatus { get; set; } public List OrderItems { get; set; } = new List(); - public Address ShippingAddress { get; set; } = default!; // << HINZUFÜGEN >> - public Address BillingAddress { get; set; } = default!; // << HINZUFÜGEN >> + public AddressDto ShippingAddress { get; set; } = default!; // << KORREKTUR: Typ zu AddressDto geändert >> + public AddressDto BillingAddress { get; set; } = default!; // << KORREKTUR: Typ zu AddressDto geändert >> + public string PaymentMethod { get; set; } = string.Empty; // << HINZUFÜGEN >> } } diff --git a/Webshop.Application/Services/Admin/AdminOrderService.cs b/Webshop.Application/Services/Admin/AdminOrderService.cs index 7aa6a17..083cae4 100644 --- a/Webshop.Application/Services/Admin/AdminOrderService.cs +++ b/Webshop.Application/Services/Admin/AdminOrderService.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Webshop.Application.DTOs.Customers; using Webshop.Application.DTOs.Orders; using Webshop.Domain.Enums; // Wichtig für Enum-Konvertierung using Webshop.Domain.Interfaces; @@ -45,13 +46,32 @@ namespace Webshop.Application.Services.Admin OrderNumber = order.OrderNumber, OrderDate = order.OrderDate, CustomerId = order.CustomerId, - // << KORREKTUR: String zu Enum parsen >> Status = Enum.TryParse(order.OrderStatus, true, out var orderStatus) ? orderStatus : OrderStatus.Pending, TotalAmount = order.OrderTotal, - ShippingAddress = order.ShippingAddress, // Annahme: Address DTO Mapping - BillingAddress = order.BillingAddress, // Annahme: Address DTO Mapping + + // << KORREKTUR: Manuelles Mapping von Address-Entität zu AddressDto >> + ShippingAddress = new AddressDto + { + Id = order.ShippingAddress.Id, + Street = order.ShippingAddress.Street, + HouseNumber = order.ShippingAddress.HouseNumber, + City = order.ShippingAddress.City, + PostalCode = order.ShippingAddress.PostalCode, + Country = order.ShippingAddress.Country, + Type = order.ShippingAddress.Type + }, + BillingAddress = new AddressDto + { + Id = order.BillingAddress.Id, + Street = order.BillingAddress.Street, + HouseNumber = order.BillingAddress.HouseNumber, + City = order.BillingAddress.City, + PostalCode = order.BillingAddress.PostalCode, + Country = order.BillingAddress.Country, + Type = order.BillingAddress.Type + }, + PaymentMethod = order.PaymentMethod, - // << KORREKTUR: String zu Enum parsen >> PaymentStatus = Enum.TryParse(order.PaymentStatus, true, out var paymentStatus) ? paymentStatus : PaymentStatus.Pending, OrderItems = order.OrderItems.Select(oi => new OrderItemDto { diff --git a/Webshop.Application/Services/Customers/OrderService.cs b/Webshop.Application/Services/Customers/OrderService.cs index 2fe1a2b..3003cf6 100644 --- a/Webshop.Application/Services/Customers/OrderService.cs +++ b/Webshop.Application/Services/Customers/OrderService.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Webshop.Application.DTOs.Customers; using Webshop.Application.DTOs.Orders; using Webshop.Domain.Entities; using Webshop.Domain.Enums; @@ -163,24 +164,23 @@ namespace Webshop.Application.Services.Customers var customer = await _customerRepository.GetByUserIdAsync(userId); if (customer == null) { - return null; // Kein Kunde, kann keine Bestellung abrufen + return null; } - // Finde die Bestellung und stelle sicher, dass sie zum eingeloggten Kunden gehört var order = await _context.Orders - .Include(o => o.BillingAddress) - .Include(o => o.ShippingAddress) - .Include(o => o.PaymentMethodInfo) // << HINZUFÜGEN, um PaymentMethodInfo zu laden >> - .Include(o => o.ShippingMethodInfo) // << HINZUFÜGEN, um ShippingMethodInfo zu laden >> + .Include(o => o.BillingAddress) // Lade die Address-Entität + .Include(o => o.ShippingAddress) // Lade die Address-Entität + .Include(o => o.PaymentMethodInfo) .Include(o => o.OrderItems) - .ThenInclude(oi => oi.Product) // Optional: Dann das Produkt laden + .ThenInclude(oi => oi.Product) .FirstOrDefaultAsync(o => o.Id == orderId && o.CustomerId == customer.Id); if (order == null) { - return null; // Bestellung nicht gefunden oder gehört nicht diesem Kunden + return null; } + // << KORREKTUR: Manuelles Mapping von Address-Entität zu AddressDto >> return new OrderDetailDto { Id = order.Id, @@ -189,9 +189,27 @@ namespace Webshop.Application.Services.Customers CustomerId = order.CustomerId, Status = Enum.TryParse(order.OrderStatus, true, out var orderStatus) ? orderStatus : OrderStatus.Pending, TotalAmount = order.OrderTotal, - ShippingAddress = order.ShippingAddress, // Annahme: Address DTO Mapping - BillingAddress = order.BillingAddress, // Annahme: Address DTO Mapping - PaymentMethod = order.PaymentMethod, // << KORREKTUR: Dies ist ein String in Ihrer Entität >> + ShippingAddress = new AddressDto + { + Id = order.ShippingAddress.Id, + Street = order.ShippingAddress.Street, + HouseNumber = order.ShippingAddress.HouseNumber, + City = order.ShippingAddress.City, + PostalCode = order.ShippingAddress.PostalCode, + Country = order.ShippingAddress.Country, + Type = order.ShippingAddress.Type + }, + BillingAddress = new AddressDto + { + Id = order.BillingAddress.Id, + Street = order.BillingAddress.Street, + HouseNumber = order.BillingAddress.HouseNumber, + City = order.BillingAddress.City, + PostalCode = order.BillingAddress.PostalCode, + Country = order.BillingAddress.Country, + Type = order.BillingAddress.Type + }, + PaymentMethod = order.PaymentMethod, PaymentStatus = Enum.TryParse(order.PaymentStatus, true, out var paymentStatus) ? paymentStatus : PaymentStatus.Pending, ShippingTrackingNumber = order.ShippingTrackingNumber, ShippedDate = order.ShippedDate, diff --git a/Webshop.Infrastructure/Repositories/CustomerAddressesRepository.cs b/Webshop.Infrastructure/Repositories/CustomerAddressesRepository.cs deleted file mode 100644 index 1299b62..0000000 --- a/Webshop.Infrastructure/Repositories/CustomerAddressesRepository.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Webshop.Infrastructure.Repositories -{ - internal class CustomerAddressesRepository - { - } -}