Compare commits

..

2 Commits

Author SHA1 Message Date
Tizian.Breuch
b29ecb77df mig 4
All checks were successful
Branch - test - Build and Push Backend API Docker Image / build-and-push (push) Successful in 25s
2025-11-20 15:37:38 +01:00
Tizian.Breuch
063e8418f8 changes 2025-11-20 15:37:13 +01:00
4 changed files with 1419 additions and 4 deletions

View File

@@ -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; }
}
}

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();

File diff suppressed because it is too large Load Diff

View File

@@ -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)
{
}
}
}