From 642ff5872d463027ecc530fce3d13f40e2cde09e Mon Sep 17 00:00:00 2001 From: "Tizian.Breuch" Date: Fri, 7 Nov 2025 10:50:37 +0100 Subject: [PATCH] test bild upload --- .../Services/Admin/AdminProductService.cs | 2 +- .../Repositories/ProductRepository.cs | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Webshop.Application/Services/Admin/AdminProductService.cs b/Webshop.Application/Services/Admin/AdminProductService.cs index ae263c5..f33c102 100644 --- a/Webshop.Application/Services/Admin/AdminProductService.cs +++ b/Webshop.Application/Services/Admin/AdminProductService.cs @@ -34,7 +34,7 @@ namespace Webshop.Application.Services.Admin #region Unchanged Methods public async Task>> GetAllAdminProductsAsync() { - var products = await _context.Products.Include(p => p.Images).Include(p => p.Productcategories).OrderBy(p => p.Name).ToListAsync(); + var products = await _context.Products.AsNoTracking().Include(p => p.Images).Include(p => p.Productcategories).OrderBy(p => p.Name).ToListAsync(); var dtos = products.Select(MapToAdminDto).ToList(); return ServiceResult.Ok>(dtos); } diff --git a/Webshop.Infrastructure/Repositories/ProductRepository.cs b/Webshop.Infrastructure/Repositories/ProductRepository.cs index 394d5af..543d5e5 100644 --- a/Webshop.Infrastructure/Repositories/ProductRepository.cs +++ b/Webshop.Infrastructure/Repositories/ProductRepository.cs @@ -20,17 +20,21 @@ namespace Webshop.Infrastructure.Repositories public async Task> GetAllProductsAsync() { - return await _context.Products.ToListAsync(); + return await _context.Products.AsNoTracking().ToListAsync(); } public async Task GetProductByIdAsync(Guid id) { - return await _context.Products.FindAsync(id); + return await _context.Products + .AsNoTracking() + .FirstOrDefaultAsync(p => p.Id == id); } public async Task GetBySlugAsync(string slug) { - return await _context.Products.FirstOrDefaultAsync(p => p.Slug == slug && p.IsActive); + return await _context.Products + .AsNoTracking() + .FirstOrDefaultAsync(p => p.Slug == slug && p.IsActive); } // --- NEUE METHODE ---