order
This commit is contained in:
@@ -1,18 +1,90 @@
|
||||
// Auto-generiert von CreateWebshopFiles.ps1
|
||||
// src/Webshop.Application/Services/Admin/AdminOrderService.cs
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Webshop.Application.Services.Admin.Interfaces;
|
||||
|
||||
using Webshop.Application.DTOs.Orders;
|
||||
using Webshop.Domain.Enums; // Wichtig für Enum-Konvertierung
|
||||
using Webshop.Domain.Interfaces;
|
||||
|
||||
namespace Webshop.Application.Services.Admin
|
||||
{
|
||||
public class AdminOrderService : IAdminOrderService
|
||||
{
|
||||
// Fügen Sie hier Abhängigkeiten per Dependency Injection hinzu (z.B. Repositories)
|
||||
private readonly IOrderRepository _orderRepository;
|
||||
|
||||
// public AdminOrderService(IYourRepository repository) { }
|
||||
public AdminOrderService(IOrderRepository orderRepository)
|
||||
{
|
||||
_orderRepository = orderRepository;
|
||||
}
|
||||
|
||||
// Fügen Sie hier Service-Methoden hinzu
|
||||
public async Task<IEnumerable<OrderSummaryDto>> GetAllOrdersAsync()
|
||||
{
|
||||
var orders = await _orderRepository.GetAllAsync();
|
||||
return orders.Select(o => new OrderSummaryDto
|
||||
{
|
||||
Id = o.Id,
|
||||
OrderNumber = o.OrderNumber,
|
||||
OrderDate = o.OrderDate,
|
||||
CustomerName = o.Customer != null ? $"{o.Customer.FirstName} {o.Customer.LastName}" : o.GuestEmail ?? "Gastbestellung",
|
||||
TotalAmount = o.OrderTotal,
|
||||
// << KORREKTUR: String zu Enum parsen >>
|
||||
Status = Enum.TryParse<OrderStatus>(o.OrderStatus, true, out var orderStatus) ? orderStatus : OrderStatus.Pending,
|
||||
PaymentStatus = Enum.TryParse<PaymentStatus>(o.PaymentStatus, true, out var paymentStatus) ? paymentStatus : PaymentStatus.Pending
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
public async Task<OrderDetailDto?> GetOrderByIdAsync(Guid id)
|
||||
{
|
||||
var order = await _orderRepository.GetByIdAsync(id);
|
||||
if (order == null) return null;
|
||||
|
||||
return new OrderDetailDto
|
||||
{
|
||||
Id = order.Id,
|
||||
OrderNumber = order.OrderNumber,
|
||||
OrderDate = order.OrderDate,
|
||||
CustomerId = order.CustomerId,
|
||||
// << KORREKTUR: String zu Enum parsen >>
|
||||
Status = Enum.TryParse<OrderStatus>(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: String zu Enum parsen >>
|
||||
PaymentStatus = Enum.TryParse<PaymentStatus>(order.PaymentStatus, true, out var paymentStatus) ? paymentStatus : PaymentStatus.Pending,
|
||||
OrderItems = order.OrderItems.Select(oi => new OrderItemDto
|
||||
{
|
||||
Id = oi.Id,
|
||||
ProductId = oi.ProductId,
|
||||
ProductVariantId = oi.ProductVariantId,
|
||||
ProductName = oi.ProductName,
|
||||
ProductSKU = oi.ProductSKU,
|
||||
Quantity = oi.Quantity,
|
||||
UnitPrice = oi.UnitPrice,
|
||||
TotalPrice = oi.TotalPrice
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<(bool Success, string? ErrorMessage)> UpdateOrderStatusAsync(Guid id, OrderStatus newStatus)
|
||||
{
|
||||
var order = await _orderRepository.GetByIdAsync(id);
|
||||
if (order == null)
|
||||
{
|
||||
return (false, "Bestellung nicht gefunden.");
|
||||
}
|
||||
|
||||
// << KORREKTUR: Enum zu String konvertieren >>
|
||||
order.OrderStatus = newStatus.ToString();
|
||||
|
||||
if (newStatus == OrderStatus.Shipped && string.IsNullOrEmpty(order.ShippingTrackingNumber))
|
||||
{
|
||||
// Hier könnten Sie Logik hinzufügen, um eine Tracking-Nummer zu verlangen
|
||||
}
|
||||
|
||||
await _orderRepository.UpdateAsync(order);
|
||||
return (true, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,16 @@
|
||||
// Auto-generiert von CreateWebshopFiles.ps1
|
||||
// src/Webshop.Application/Services/Admin/IAdminOrderService.cs
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Webshop.Application.DTOs;
|
||||
using Webshop.Application.DTOs.Auth;
|
||||
using Webshop.Application.DTOs.Users;
|
||||
using Webshop.Application.DTOs.Orders;
|
||||
using Webshop.Domain.Enums;
|
||||
|
||||
|
||||
namespace Webshop.Application.Services.Admin.Interfaces
|
||||
namespace Webshop.Application.Services.Admin
|
||||
{
|
||||
public interface IAdminOrderService
|
||||
{
|
||||
// Fügen Sie hier Methodensignaturen hinzu
|
||||
Task<IEnumerable<OrderSummaryDto>> GetAllOrdersAsync();
|
||||
Task<OrderDetailDto?> GetOrderByIdAsync(Guid id);
|
||||
Task<(bool Success, string? ErrorMessage)> UpdateOrderStatusAsync(Guid id, OrderStatus newStatus);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user