This commit is contained in:
Tizian.Breuch
2025-11-20 15:37:13 +01:00
parent 7a0e56e27a
commit 063e8418f8
2 changed files with 31 additions and 4 deletions

View File

@@ -120,12 +120,39 @@ namespace Webshop.Application.Services.Admin
return ServiceResult.Fail(ServiceResultType.NotFound, $"Produkt mit ID '{productDto.Id}' nicht gefunden.");
}
// SCHRITT 2: Setze SOFORT den Concurrency Token am "sauberen" Objekt.
if (productDto.RowVersion != null && productDto.RowVersion.Length > 0)
// --- CONCURRENCY CHECK ---
if (!string.IsNullOrEmpty(productDto.RowVersion))
{
_context.Entry(existingProduct).Property(p => p.RowVersion).OriginalValue = productDto.RowVersion;
try
{
// <<<<<< WICHTIGE KORREKTUR HIER >>>>>>
// FormData wandelt "+" oft in " " um. Das reparieren wir hier:
string fixedRowVersion = productDto.RowVersion.Replace(" ", "+");
// 1. Umwandlung von String (Base64) zu Byte-Array
byte[] incomingRowVersion = Convert.FromBase64String(fixedRowVersion);
// DEBUG-LOGGING
string dbValue = Convert.ToBase64String(existingProduct.RowVersion ?? new byte[0]);
Console.WriteLine($"DB RowVersion: {dbValue}");
Console.WriteLine($"Frontend RowVersion: {fixedRowVersion}"); // Logge den reparierten Wert
if (dbValue != fixedRowVersion)
{
Console.WriteLine("!!! WARNUNG: Versionen stimmen nicht <20>berein !!!");
}
// 2. Setze den Originalwert f<>r EF Core
_context.Entry(existingProduct).Property(p => p.RowVersion).OriginalValue = incomingRowVersion;
}
catch (FormatException)
{
return ServiceResult.Fail(ServiceResultType.Failure, "RowVersion Format ist ung<6E>ltig.");
}
}
// SCHRITT 3: Lade jetzt die Relationen explizit nach.
await _context.Entry(existingProduct).Collection(p => p.Images).LoadAsync();
await _context.Entry(existingProduct).Collection(p => p.Productcategories).LoadAsync();