shipping method weight

This commit is contained in:
Tizian.Breuch
2025-11-26 09:56:05 +01:00
parent e42c4d6741
commit efc70084c3
7 changed files with 1472 additions and 41 deletions

View File

@@ -1,14 +1,13 @@
// src/Webshop.Application/Services/Admin/AdminShippingMethodService.cs
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore; // Hinzufügen für .AnyAsync
using Microsoft.EntityFrameworkCore;
using Webshop.Application;
using Webshop.Application.DTOs.Shipping;
using Webshop.Domain.Entities;
using Webshop.Domain.Interfaces;
using Webshop.Infrastructure.Data; // Hinzufügen für DbContext
using Webshop.Infrastructure.Data;
namespace Webshop.Application.Services.Admin
{
@@ -55,14 +54,15 @@ namespace Webshop.Application.Services.Admin
Description = shippingMethodDto.Description,
BaseCost = shippingMethodDto.Cost,
IsActive = shippingMethodDto.IsActive,
// +++ KORREKTUR +++
MinDeliveryDays = shippingMethodDto.MinDeliveryDays,
MaxDeliveryDays = shippingMethodDto.MaxDeliveryDays
MaxDeliveryDays = shippingMethodDto.MaxDeliveryDays,
// NEU: Gewichte mappen
MinWeight = shippingMethodDto.MinWeight,
MaxWeight = shippingMethodDto.MaxWeight
};
await _shippingMethodRepository.AddAsync(newMethod);
// Verwende MapToDto, um eine konsistente Antwort zu gewährleisten
return ServiceResult.Ok(MapToDto(newMethod));
}
@@ -75,6 +75,7 @@ namespace Webshop.Application.Services.Admin
}
var allMethods = await _shippingMethodRepository.GetAllAsync();
// Prüfen, ob der Name von einer ANDEREN Methode bereits verwendet wird
if (allMethods.Any(sm => sm.Name.Equals(shippingMethodDto.Name, StringComparison.OrdinalIgnoreCase) && sm.Id != shippingMethodDto.Id))
{
return ServiceResult.Fail(ServiceResultType.Conflict, $"Eine andere Versandmethode mit dem Namen '{shippingMethodDto.Name}' existiert bereits.");
@@ -84,9 +85,11 @@ namespace Webshop.Application.Services.Admin
existingMethod.Description = shippingMethodDto.Description;
existingMethod.BaseCost = shippingMethodDto.Cost;
existingMethod.IsActive = shippingMethodDto.IsActive;
// +++ KORREKTUR +++
existingMethod.MinDeliveryDays = shippingMethodDto.MinDeliveryDays;
existingMethod.MaxDeliveryDays = shippingMethodDto.MaxDeliveryDays;
// NEU: Gewichte aktualisieren
existingMethod.MinWeight = shippingMethodDto.MinWeight;
existingMethod.MaxWeight = shippingMethodDto.MaxWeight;
await _shippingMethodRepository.UpdateAsync(existingMethod);
return ServiceResult.Ok();
@@ -119,9 +122,11 @@ namespace Webshop.Application.Services.Admin
Description = sm.Description,
Cost = sm.BaseCost,
IsActive = sm.IsActive,
// +++ KORREKTUR +++
MinDeliveryDays = sm.MinDeliveryDays,
MaxDeliveryDays = sm.MaxDeliveryDays
MaxDeliveryDays = sm.MaxDeliveryDays,
// NEU: Gewichte ins DTO übertragen
MinWeight = sm.MinWeight,
MaxWeight = sm.MaxWeight
};
}
}