bilder main image change
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:
@@ -22,11 +22,12 @@ namespace Webshop.Application.DTOs.Products
|
|||||||
[Required]
|
[Required]
|
||||||
public string Slug { get; set; }
|
public string Slug { get; set; }
|
||||||
|
|
||||||
// << ZURÜCK ZU IFormFile >>
|
|
||||||
public IFormFile? MainImageFile { get; set; }
|
public IFormFile? MainImageFile { get; set; }
|
||||||
public List<IFormFile>? AdditionalImageFiles { get; set; }
|
public List<IFormFile>? AdditionalImageFiles { get; set; }
|
||||||
public List<Guid>? ImagesToDelete { get; set; }
|
public List<Guid>? ImagesToDelete { get; set; }
|
||||||
|
|
||||||
|
public Guid? SetMainImageId { get; set; }
|
||||||
|
|
||||||
public List<Guid>? CategorieIds { get; set; } = new List<Guid>();
|
public List<Guid>? CategorieIds { get; set; } = new List<Guid>();
|
||||||
|
|
||||||
public decimal? Weight { get; set; }
|
public decimal? Weight { get; set; }
|
||||||
|
|||||||
@@ -189,6 +189,33 @@ namespace Webshop.Application.Services.Admin
|
|||||||
|
|
||||||
imagesChanged = true;
|
imagesChanged = true;
|
||||||
}
|
}
|
||||||
|
// >>> NEU: A2.5 Szenario: BESTEHENDES Bild als Hauptbild <<<
|
||||||
|
else if (productDto.SetMainImageId.HasValue)
|
||||||
|
{
|
||||||
|
// Wir suchen das Bild in der Liste, die wir schon aus der DB geladen haben
|
||||||
|
var targetImage = existingProduct.Images.FirstOrDefault(img => img.Id == productDto.SetMainImageId.Value);
|
||||||
|
|
||||||
|
// Nur ausf<73>hren, wenn Bild existiert und noch nicht Main ist
|
||||||
|
if (targetImage != null && !targetImage.IsMainImage)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"---- Setze existierendes Bild {targetImage.Id} als MAIN ----");
|
||||||
|
|
||||||
|
// 1. Alle Bilder auf "Nicht-Main" setzen
|
||||||
|
foreach (var img in existingProduct.Images)
|
||||||
|
{
|
||||||
|
img.IsMainImage = false;
|
||||||
|
// Optional: Ordnung korrigieren, damit Main immer vorne ist
|
||||||
|
if (img.DisplayOrder == 1) img.DisplayOrder = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. Das gew<65>hlte Bild auf Main setzen
|
||||||
|
targetImage.IsMainImage = true;
|
||||||
|
targetImage.DisplayOrder = 1;
|
||||||
|
|
||||||
|
// Da wir hier getrackte Entities <20>ndern, generiert EF Core automatisch UPDATEs
|
||||||
|
imagesChanged = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// A3. Zusatzbilder
|
// A3. Zusatzbilder
|
||||||
if (productDto.AdditionalImageFiles != null && productDto.AdditionalImageFiles.Any())
|
if (productDto.AdditionalImageFiles != null && productDto.AdditionalImageFiles.Any())
|
||||||
|
|||||||
Reference in New Issue
Block a user