// src/Webshop.Application/Services/Admin/AdminShippingMethodService.cs using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Webshop.Application.DTOs.Shipping; using Webshop.Domain.Entities; using Webshop.Domain.Interfaces; namespace Webshop.Application.Services.Admin { public class AdminShippingMethodService : IAdminShippingMethodService { private readonly IShippingMethodRepository _shippingMethodRepository; public AdminShippingMethodService(IShippingMethodRepository shippingMethodRepository) { _shippingMethodRepository = shippingMethodRepository; } public async Task> GetAllAsync() { var methods = await _shippingMethodRepository.GetAllAsync(); return methods.Select(sm => new ShippingMethodDto { Id = sm.Id, Name = sm.Name, Description = sm.Description, Cost = sm.BaseCost, IsActive = sm.IsActive, MinDeliveryDays = 0, // Annahme, diese Felder existieren in Ihrer Entität MaxDeliveryDays = 0 // Annahme, diese Felder existieren in Ihrer Entität }).ToList(); } public async Task GetByIdAsync(Guid id) { var sm = await _shippingMethodRepository.GetByIdAsync(id); if (sm == null) return null; return new ShippingMethodDto { Id = sm.Id, Name = sm.Name, Description = sm.Description, Cost = sm.BaseCost, IsActive = sm.IsActive }; } public async Task CreateAsync(ShippingMethodDto shippingMethodDto) { var newMethod = new ShippingMethod { Id = Guid.NewGuid(), Name = shippingMethodDto.Name, Description = shippingMethodDto.Description, BaseCost = shippingMethodDto.Cost, IsActive = shippingMethodDto.IsActive }; await _shippingMethodRepository.AddAsync(newMethod); shippingMethodDto.Id = newMethod.Id; return shippingMethodDto; } public async Task UpdateAsync(ShippingMethodDto shippingMethodDto) { var existingMethod = await _shippingMethodRepository.GetByIdAsync(shippingMethodDto.Id); if (existingMethod == null) return false; existingMethod.Name = shippingMethodDto.Name; existingMethod.Description = shippingMethodDto.Description; existingMethod.BaseCost = shippingMethodDto.Cost; existingMethod.IsActive = shippingMethodDto.IsActive; await _shippingMethodRepository.UpdateAsync(existingMethod); return true; } public async Task DeleteAsync(Guid id) { var method = await _shippingMethodRepository.GetByIdAsync(id); if (method == null) return false; await _shippingMethodRepository.DeleteAsync(id); return true; } } }