Compare commits
2 Commits
7a0e56e27a
...
b29ecb77df
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b29ecb77df | ||
|
|
063e8418f8 |
@@ -36,6 +36,6 @@ namespace Webshop.Application.DTOs.Products
|
||||
public bool IsFeatured { get; set; }
|
||||
public int FeaturedDisplayOrder { get; set; }
|
||||
|
||||
public byte[]? RowVersion { get; set; }
|
||||
public string? RowVersion { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
1366
Webshop.Infrastructure/Migrations/20251120143728_rowversion4.Designer.cs
generated
Normal file
1366
Webshop.Infrastructure/Migrations/20251120143728_rowversion4.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,22 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Webshop.Infrastructure.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class rowversion4 : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user