diff --git a/Webshop.Application/Services/Admin/AdminProductService.cs b/Webshop.Application/Services/Admin/AdminProductService.cs index 55ae97d..744bb84 100644 --- a/Webshop.Application/Services/Admin/AdminProductService.cs +++ b/Webshop.Application/Services/Admin/AdminProductService.cs @@ -132,7 +132,7 @@ namespace Webshop.Application.Services.Admin image.DisplayOrder = currentOrder++; } - await _productRepository.UpdateProductAsync(); + await _productRepository.UpdateProductAsync(existingProduct); return ServiceResult.Ok(); } diff --git a/Webshop.Domain/Interfaces/IProductRepository.cs b/Webshop.Domain/Interfaces/IProductRepository.cs index 32090ca..152b5ce 100644 --- a/Webshop.Domain/Interfaces/IProductRepository.cs +++ b/Webshop.Domain/Interfaces/IProductRepository.cs @@ -13,7 +13,7 @@ namespace Webshop.Domain.Interfaces Task GetBySlugAsync(string slug); Task AddProductAsync(Product product); Task GetProductByIdForUpdateAsync(Guid id); // NEU - Task UpdateProductAsync(); // GEÄNDERT (parameterlos) + Task UpdateProductAsync(Product product); Task DeleteProductAsync(Guid id); } } \ No newline at end of file diff --git a/Webshop.Infrastructure/Repositories/ProductRepository.cs b/Webshop.Infrastructure/Repositories/ProductRepository.cs index 066a7f4..e5f32cb 100644 --- a/Webshop.Infrastructure/Repositories/ProductRepository.cs +++ b/Webshop.Infrastructure/Repositories/ProductRepository.cs @@ -49,8 +49,14 @@ namespace Webshop.Infrastructure.Repositories } // --- KORRIGIERTE UPDATE-METHODE (OHNE PARAMETER) --- - public async Task UpdateProductAsync() + public async Task UpdateProductAsync(Product product) { + // Wir sagen dem DbContext explizit, dass der Zustand dieser Entität "Modifiziert" ist. + // Das zwingt EF Core dazu, ALLE Eigenschaften der Entität in der UPDATE-Anweisung zu berücksichtigen. + // Es umgeht alle möglichen Probleme mit dem Change Tracking, die durch verschiedene Kontexte + // oder komplexe Beziehungs-Updates entstehen können. + _context.Entry(product).State = EntityState.Modified; + await _context.SaveChangesAsync(); }