Adress und shipping

This commit is contained in:
Tizian.Breuch
2025-08-01 09:09:49 +02:00
parent 7fc0b32c17
commit 14daa831cb
14 changed files with 460 additions and 47 deletions

View File

@@ -0,0 +1,90 @@
// 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<IEnumerable<ShippingMethodDto>> 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<ShippingMethodDto?> 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<ShippingMethodDto> 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<bool> 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<bool> DeleteAsync(Guid id)
{
var method = await _shippingMethodRepository.GetByIdAsync(id);
if (method == null) return false;
await _shippingMethodRepository.DeleteAsync(id);
return true;
}
}
}