rest
All checks were successful
Branch - test - Build and Push Backend API Docker Image / build-and-push (push) Successful in 26s
All checks were successful
Branch - test - Build and Push Backend API Docker Image / build-and-push (push) Successful in 26s
This commit is contained in:
@@ -111,10 +111,11 @@ namespace Webshop.Application.Services.Admin
|
|||||||
#region Unchanged Methods
|
#region Unchanged Methods
|
||||||
public async Task<ServiceResult> UpdateAdminProductAsync(UpdateAdminProductDto productDto)
|
public async Task<ServiceResult> UpdateAdminProductAsync(UpdateAdminProductDto productDto)
|
||||||
{
|
{
|
||||||
// 1. Produkt laden (bleibt gleich)
|
// 1. Produkt laden
|
||||||
var existingProduct = await _context.Products
|
var existingProduct = await _context.Products
|
||||||
.Include(p => p.Images)
|
// Wir brauchen die Includes f<>r diesen Test nicht, das macht es schneller
|
||||||
.Include(p => p.Productcategories)
|
// .Include(p => p.Images)
|
||||||
|
// .Include(p => p.Productcategories)
|
||||||
.FirstOrDefaultAsync(p => p.Id == productDto.Id);
|
.FirstOrDefaultAsync(p => p.Id == productDto.Id);
|
||||||
|
|
||||||
if (existingProduct == null)
|
if (existingProduct == null)
|
||||||
@@ -122,57 +123,21 @@ namespace Webshop.Application.Services.Admin
|
|||||||
return ServiceResult.Fail(ServiceResultType.NotFound, $"Produkt mit ID '{productDto.Id}' nicht gefunden.");
|
return ServiceResult.Fail(ServiceResultType.NotFound, $"Produkt mit ID '{productDto.Id}' nicht gefunden.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. Pr<EFBFBD>fungen (bleibt gleich)
|
// 2. NUR den Namen <20>ndern
|
||||||
var skuExists = await _context.Products.AnyAsync(p => p.SKU == productDto.SKU && p.Id != productDto.Id);
|
Console.WriteLine($"---- DEBUG: <20>ndere Namen von '{existingProduct.Name}' zu '{productDto.Name}' ----");
|
||||||
if (skuExists) { return ServiceResult.Fail(ServiceResultType.Conflict, $"Ein anderes Produkt mit der SKU '{productDto.SKU}' existiert bereits."); }
|
|
||||||
|
|
||||||
var slugExists = await _context.Products.AnyAsync(p => p.Slug == productDto.Slug && p.Id != productDto.Id);
|
|
||||||
if (slugExists) { return ServiceResult.Fail(ServiceResultType.Conflict, $"Ein anderes Produkt mit dem Slug '{productDto.Slug}' existiert bereits."); }
|
|
||||||
|
|
||||||
// 3. Modifikationen (bleibt gleich)
|
|
||||||
if (productDto.ImagesToDelete != null && productDto.ImagesToDelete.Any()) { /* ... */ }
|
|
||||||
if (productDto.MainImageFile != null) { /* ... */ }
|
|
||||||
if (productDto.AdditionalImageFiles != null && productDto.AdditionalImageFiles.Any()) { /* ... */ }
|
|
||||||
|
|
||||||
existingProduct.Name = productDto.Name;
|
existingProduct.Name = productDto.Name;
|
||||||
existingProduct.Description = productDto.Description;
|
|
||||||
// ... all deine anderen Zuweisungen ...
|
|
||||||
existingProduct.LastModifiedDate = DateTimeOffset.UtcNow;
|
existingProduct.LastModifiedDate = DateTimeOffset.UtcNow;
|
||||||
existingProduct.Productcategories.Clear();
|
|
||||||
if (productDto.CategorieIds != null) { /* ... */ }
|
|
||||||
|
|
||||||
// ==============================================================================
|
// 3. Speichern
|
||||||
// <20>NDERUNG HIER: Wir rufen SaveChanges direkt auf dem Context auf.
|
|
||||||
// Das eliminiert das Repository als m<>gliche Fehlerquelle.
|
|
||||||
// ==============================================================================
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// await _productRepository.SaveChangesAsync(); // Alte Zeile
|
await _context.SaveChangesAsync();
|
||||||
await _context.SaveChangesAsync(); // NEUE ZEILE
|
Console.WriteLine("---- DEBUG: SaveChangesAsync erfolgreich aufgerufen. ----");
|
||||||
}
|
}
|
||||||
catch (DbUpdateConcurrencyException ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
// Wir fangen den Fehler hier ab, um mehr Details zu loggen (optional aber hilfreich)
|
Console.WriteLine($"---- DEBUG: FEHLER bei SaveChangesAsync: {ex.Message} ----");
|
||||||
Console.WriteLine("---- DbUpdateConcurrencyException Details ----");
|
throw; // Fehler weiterwerfen, damit wir es im Log sehen
|
||||||
foreach (var entry in ex.Entries)
|
|
||||||
{
|
|
||||||
if (entry.Entity is Product product)
|
|
||||||
{
|
|
||||||
var databaseValues = await entry.GetDatabaseValuesAsync();
|
|
||||||
if (databaseValues == null)
|
|
||||||
{
|
|
||||||
Console.WriteLine($"Das Produkt mit ID {product.Id} wurde in der DB gel<65>scht.");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Console.WriteLine($"Konflikt beim Produkt mit ID {product.Id}.");
|
|
||||||
// Hier k<>nntest du noch Original- vs. Datenbankwerte loggen
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Console.WriteLine("--------------------------------------------");
|
|
||||||
// Wir werfen den Fehler weiter, damit die App wie bisher reagiert
|
|
||||||
throw;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ServiceResult.Ok();
|
return ServiceResult.Ok();
|
||||||
|
|||||||
Reference in New Issue
Block a user