image änderungen
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
// Auto-generiert von CreateWebshopFiles.ps1
|
||||
// src/Webshop.Application/DTOs/Products/AdminProductDto.cs
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
namespace Webshop.Application.DTOs.Products
|
||||
{
|
||||
@@ -18,12 +16,13 @@ namespace Webshop.Application.DTOs.Products
|
||||
public bool IsInStock { get; set; } = true;
|
||||
public int StockQuantity { get; set; }
|
||||
public decimal? Weight { get; set; }
|
||||
public string? ImageUrl { get; set; }
|
||||
// << ENTFERNT: ImageUrl >>
|
||||
public string Slug { get; set; } = string.Empty;
|
||||
public DateTimeOffset CreatedDate { get; set; } = DateTimeOffset.UtcNow;
|
||||
public DateTimeOffset? LastModifiedDate { get; set; }
|
||||
public Guid? SupplierId { get; set; }
|
||||
public decimal? PurchasePrice { get; set; }
|
||||
public List<Guid> categorieIds { get; set; } = new List<Guid>();
|
||||
public List<ProductImageDto> Images { get; set; } = new List<ProductImageDto>(); // << NEU >>
|
||||
}
|
||||
}
|
||||
}
|
||||
36
Webshop.Application/DTOs/Products/CreateAdminProductDto.cs
Normal file
36
Webshop.Application/DTOs/Products/CreateAdminProductDto.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
// src/Webshop.Application/DTOs/Products/CreateAdminProductDto.cs
|
||||
using Microsoft.AspNetCore.Http; // Für IFormFile
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Webshop.Application.DTOs.Products
|
||||
{
|
||||
public class CreateAdminProductDto
|
||||
{
|
||||
[Required]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public string? Description { get; set; }
|
||||
[Required]
|
||||
public string SKU { get; set; }
|
||||
[Required]
|
||||
public decimal Price { get; set; }
|
||||
public bool IsActive { get; set; } = true;
|
||||
public bool IsInStock { get; set; } = true;
|
||||
public int StockQuantity { get; set; }
|
||||
[Required]
|
||||
public string Slug { get; set; }
|
||||
|
||||
// << NEU: Felder für den Bildupload >>
|
||||
public IFormFile? MainImageFile { get; set; }
|
||||
public List<IFormFile>? AdditionalImageFiles { get; set; }
|
||||
|
||||
public List<Guid> CategorieIds { get; set; } = new List<Guid>();
|
||||
|
||||
// ... weitere Felder, die beim Erstellen benötigt werden (z.B. SupplierId, PurchasePrice etc.) ...
|
||||
public decimal? Weight { get; set; }
|
||||
public decimal? OldPrice { get; set; }
|
||||
public Guid? SupplierId { get; set; }
|
||||
public decimal? PurchasePrice { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,8 @@
|
||||
// Auto-generiert von CreateWebshopFiles.ps1
|
||||
// src/Webshop.Application/DTOs/Products/ProductDto.cs
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Webshop.Application.DTOs.Categorie;
|
||||
|
||||
|
||||
namespace Webshop.Application.DTOs.Products
|
||||
{
|
||||
public class ProductDto
|
||||
@@ -17,8 +15,9 @@ namespace Webshop.Application.DTOs.Products
|
||||
public bool IsActive { get; set; }
|
||||
public bool IsInStock { get; set; }
|
||||
public int StockQuantity { get; set; }
|
||||
public string? ImageUrl { get; set; }
|
||||
// << ENTFERNT: ImageUrl >>
|
||||
public string Slug { get; set; } = string.Empty;
|
||||
public List<CategorieDto> categories { get; set; } = new List<CategorieDto>();
|
||||
public List<ProductImageDto> Images { get; set; } = new List<ProductImageDto>(); // << NEU >>
|
||||
}
|
||||
}
|
||||
}
|
||||
13
Webshop.Application/DTOs/Products/ProductImageDto.cs
Normal file
13
Webshop.Application/DTOs/Products/ProductImageDto.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
// src/Webshop.Application/DTOs/Products/ProductImageDto.cs
|
||||
using System;
|
||||
|
||||
namespace Webshop.Application.DTOs.Products
|
||||
{
|
||||
public class ProductImageDto
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public string Url { get; set; } = string.Empty;
|
||||
public bool IsMainImage { get; set; }
|
||||
public int DisplayOrder { get; set; }
|
||||
}
|
||||
}
|
||||
39
Webshop.Application/DTOs/Products/UpdateAdminProductDto.cs
Normal file
39
Webshop.Application/DTOs/Products/UpdateAdminProductDto.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
// src/Webshop.Application/DTOs/Products/UpdateAdminProductDto.cs
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Webshop.Application.DTOs.Products
|
||||
{
|
||||
public class UpdateAdminProductDto
|
||||
{
|
||||
[Required]
|
||||
public Guid Id { get; set; }
|
||||
[Required]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public string? Description { get; set; }
|
||||
[Required]
|
||||
public string SKU { get; set; }
|
||||
[Required]
|
||||
public decimal Price { get; set; }
|
||||
public bool IsActive { get; set; }
|
||||
public bool IsInStock { get; set; }
|
||||
public int StockQuantity { get; set; }
|
||||
[Required]
|
||||
public string Slug { get; set; }
|
||||
|
||||
// << NEU: Felder für den Bildupload und -verwaltung >>
|
||||
public IFormFile? MainImageFile { get; set; } // Optional: Neues Hauptbild hochladen
|
||||
public List<IFormFile>? AdditionalImageFiles { get; set; } // Optional: Weitere Bilder hochladen
|
||||
public List<Guid>? ImagesToDelete { get; set; } // Liste der IDs von Bildern, die gelöscht werden sollen
|
||||
|
||||
public List<Guid> CategorieIds { get; set; } = new List<Guid>();
|
||||
|
||||
// ... weitere Felder, die beim Aktualisieren benötigt werden ...
|
||||
public decimal? Weight { get; set; }
|
||||
public decimal? OldPrice { get; set; }
|
||||
public Guid? SupplierId { get; set; }
|
||||
public decimal? PurchasePrice { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,33 +1,38 @@
|
||||
// src/Webshop.Application/Services/Admin/AdminProductService.cs
|
||||
using Microsoft.EntityFrameworkCore; // << NEU: F<>r Include() und FirstOrDefaultAsync() >>
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Webshop.Domain.Entities;
|
||||
using Webshop.Domain.Interfaces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Webshop.Application.DTOs.Products; // F<>r AdminProductDto
|
||||
using Webshop.Application.Services.Admin.Interfaces; // F<>r IAdminProductService
|
||||
using Webshop.Infrastructure.Data; // << NEU: F<>r ApplicationDbContext >>
|
||||
using Webshop.Application.DTOs.Products;
|
||||
using Webshop.Application.Services.Admin.Interfaces;
|
||||
using Webshop.Infrastructure.Data;
|
||||
|
||||
namespace Webshop.Application.Services.Admin
|
||||
{
|
||||
public class AdminProductService : IAdminProductService
|
||||
{
|
||||
private readonly IProductRepository _productRepository;
|
||||
private readonly ApplicationDbContext _context; // << NEU: F<>r direkten DB-Zugriff auf Join-Tabellen >>
|
||||
private readonly IFileStorageService _fileStorageService;
|
||||
private readonly ApplicationDbContext _context;
|
||||
|
||||
public AdminProductService(IProductRepository productRepository, ApplicationDbContext context) // << NEU: DbContext injizieren >>
|
||||
public AdminProductService(
|
||||
IProductRepository productRepository,
|
||||
IFileStorageService fileStorageService,
|
||||
ApplicationDbContext context)
|
||||
{
|
||||
_productRepository = productRepository;
|
||||
_context = context; // << NEU >>
|
||||
_fileStorageService = fileStorageService;
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<AdminProductDto>> GetAllAdminProductsAsync()
|
||||
{
|
||||
// Wir verwenden den DbContext, um auch die Kategorien effizient mitzuladen
|
||||
var products = await _context.Products
|
||||
.Include(p => p.Productcategories)
|
||||
.Include(p => p.Images)
|
||||
.ToListAsync();
|
||||
|
||||
return products.Select(p => new AdminProductDto
|
||||
@@ -42,20 +47,27 @@ namespace Webshop.Application.Services.Admin
|
||||
IsInStock = p.IsInStock,
|
||||
StockQuantity = p.StockQuantity,
|
||||
Weight = p.Weight,
|
||||
ImageUrl = p.ImageUrl,
|
||||
Slug = p.Slug,
|
||||
CreatedDate = p.CreatedDate,
|
||||
LastModifiedDate = p.LastModifiedDate,
|
||||
SupplierId = p.SupplierId,
|
||||
PurchasePrice = p.PurchasePrice,
|
||||
categorieIds = p.Productcategories.Select(pc => pc.categorieId).ToList() // << NEU >>
|
||||
categorieIds = p.Productcategories.Select(pc => pc.categorieId).ToList(),
|
||||
Images = p.Images.Select(img => new ProductImageDto
|
||||
{
|
||||
Id = img.Id,
|
||||
Url = img.Url,
|
||||
IsMainImage = img.IsMainImage,
|
||||
DisplayOrder = img.DisplayOrder
|
||||
}).ToList()
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
public async Task<AdminProductDto?> GetAdminProductByIdAsync(Guid id)
|
||||
{
|
||||
var product = await _context.Products
|
||||
.Include(p => p.Productcategories) // << NEU: Lade die Join-Tabelle mit >>
|
||||
.Include(p => p.Productcategories)
|
||||
.Include(p => p.Images)
|
||||
.FirstOrDefaultAsync(p => p.Id == id);
|
||||
|
||||
if (product == null) return null;
|
||||
@@ -72,83 +84,100 @@ namespace Webshop.Application.Services.Admin
|
||||
IsInStock = product.IsInStock,
|
||||
StockQuantity = product.StockQuantity,
|
||||
Weight = product.Weight,
|
||||
ImageUrl = product.ImageUrl,
|
||||
Slug = product.Slug,
|
||||
CreatedDate = product.CreatedDate,
|
||||
LastModifiedDate = product.LastModifiedDate,
|
||||
SupplierId = product.SupplierId,
|
||||
PurchasePrice = product.PurchasePrice,
|
||||
categorieIds = product.Productcategories.Select(pc => pc.categorieId).ToList() // << NEU: Mappe die categorieIds >>
|
||||
categorieIds = product.Productcategories.Select(pc => pc.categorieId).ToList(),
|
||||
Images = product.Images.Select(img => new ProductImageDto
|
||||
{
|
||||
Id = img.Id,
|
||||
Url = img.Url,
|
||||
IsMainImage = img.IsMainImage,
|
||||
DisplayOrder = img.DisplayOrder
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<AdminProductDto> CreateAdminProductAsync(AdminProductDto productDto)
|
||||
public async Task<AdminProductDto> CreateAdminProductAsync(CreateAdminProductDto productDto)
|
||||
{
|
||||
var images = new List<ProductImage>();
|
||||
|
||||
if (productDto.MainImageFile != null)
|
||||
{
|
||||
await using var stream = productDto.MainImageFile.OpenReadStream();
|
||||
var url = await _fileStorageService.SaveFileAsync(stream, productDto.MainImageFile.FileName, productDto.MainImageFile.ContentType);
|
||||
images.Add(new ProductImage { Url = url, IsMainImage = true, DisplayOrder = 1 });
|
||||
}
|
||||
if (productDto.AdditionalImageFiles != null)
|
||||
{
|
||||
int order = 2;
|
||||
foreach (var file in productDto.AdditionalImageFiles)
|
||||
{
|
||||
await using var stream = file.OpenReadStream();
|
||||
var url = await _fileStorageService.SaveFileAsync(stream, file.FileName, file.ContentType);
|
||||
images.Add(new ProductImage { Url = url, IsMainImage = false, DisplayOrder = order++ });
|
||||
}
|
||||
}
|
||||
|
||||
var newProduct = new Product
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
Name = productDto.Name,
|
||||
Description = productDto.Description,
|
||||
SKU = productDto.SKU,
|
||||
Price = productDto.Price,
|
||||
OldPrice = productDto.OldPrice,
|
||||
IsActive = productDto.IsActive,
|
||||
IsInStock = productDto.IsInStock,
|
||||
StockQuantity = productDto.StockQuantity,
|
||||
Weight = productDto.Weight,
|
||||
ImageUrl = productDto.ImageUrl,
|
||||
Slug = productDto.Slug,
|
||||
CreatedDate = DateTimeOffset.UtcNow,
|
||||
SupplierId = productDto.SupplierId,
|
||||
PurchasePrice = productDto.PurchasePrice,
|
||||
Productcategories = new List<Productcategorie>() // Initialisiere die Collection
|
||||
Images = images,
|
||||
Productcategories = productDto.CategorieIds.Select(cId => new Productcategorie { categorieId = cId }).ToList()
|
||||
};
|
||||
|
||||
// << NEU: F<>ge die Kategorien hinzu >>
|
||||
foreach (var categorieId in productDto.categorieIds)
|
||||
{
|
||||
newProduct.Productcategories.Add(new Productcategorie { categorieId = categorieId });
|
||||
}
|
||||
await _productRepository.AddProductAsync(newProduct);
|
||||
|
||||
await _productRepository.AddProductAsync(newProduct); // << KORREKT: VERWENDET AddProductAsync >>
|
||||
|
||||
productDto.Id = newProduct.Id;
|
||||
return productDto;
|
||||
return (await GetAdminProductByIdAsync(newProduct.Id))!;
|
||||
}
|
||||
|
||||
public async Task<bool> UpdateAdminProductAsync(AdminProductDto productDto)
|
||||
public async Task<bool> UpdateAdminProductAsync(UpdateAdminProductDto productDto)
|
||||
{
|
||||
var existingProduct = await _context.Products
|
||||
.Include(p => p.Productcategories) // Lade die aktuellen Zuweisungen
|
||||
.Include(p => p.Images)
|
||||
.Include(p => p.Productcategories)
|
||||
.FirstOrDefaultAsync(p => p.Id == productDto.Id);
|
||||
|
||||
if (existingProduct == null) return false;
|
||||
|
||||
// Aktualisiere die direkten Eigenschaften des Produkts
|
||||
if (productDto.ImagesToDelete != null)
|
||||
{
|
||||
var imagesToRemove = existingProduct.Images.Where(img => productDto.ImagesToDelete.Contains(img.Id)).ToList();
|
||||
_context.ProductImages.RemoveRange(imagesToRemove);
|
||||
}
|
||||
if (productDto.MainImageFile != null)
|
||||
{
|
||||
var existingMainImage = existingProduct.Images.FirstOrDefault(img => img.IsMainImage);
|
||||
if (existingMainImage != null) _context.ProductImages.Remove(existingMainImage);
|
||||
|
||||
await using var stream = productDto.MainImageFile.OpenReadStream();
|
||||
var url = await _fileStorageService.SaveFileAsync(stream, productDto.MainImageFile.FileName, productDto.MainImageFile.ContentType);
|
||||
existingProduct.Images.Add(new ProductImage { Url = url, IsMainImage = true, DisplayOrder = 1 });
|
||||
}
|
||||
if (productDto.AdditionalImageFiles != null)
|
||||
{
|
||||
int displayOrder = (existingProduct.Images.Any() ? existingProduct.Images.Max(i => i.DisplayOrder) : 0) + 1;
|
||||
foreach (var file in productDto.AdditionalImageFiles)
|
||||
{
|
||||
await using var stream = file.OpenReadStream();
|
||||
var url = await _fileStorageService.SaveFileAsync(stream, file.FileName, file.ContentType);
|
||||
existingProduct.Images.Add(new ProductImage { Url = url, IsMainImage = false, DisplayOrder = displayOrder++ });
|
||||
}
|
||||
}
|
||||
|
||||
existingProduct.Name = productDto.Name;
|
||||
existingProduct.Description = productDto.Description;
|
||||
existingProduct.SKU = productDto.SKU;
|
||||
existingProduct.Price = productDto.Price;
|
||||
existingProduct.OldPrice = productDto.OldPrice;
|
||||
existingProduct.IsActive = productDto.IsActive;
|
||||
existingProduct.IsInStock = productDto.IsInStock;
|
||||
existingProduct.StockQuantity = productDto.StockQuantity;
|
||||
existingProduct.Weight = productDto.Weight;
|
||||
existingProduct.ImageUrl = productDto.ImageUrl;
|
||||
existingProduct.Slug = productDto.Slug;
|
||||
existingProduct.SupplierId = productDto.SupplierId;
|
||||
existingProduct.PurchasePrice = productDto.PurchasePrice;
|
||||
existingProduct.LastModifiedDate = DateTimeOffset.UtcNow;
|
||||
// ... (restliche Felder aktualisieren) ...
|
||||
|
||||
// << NEU: Kategorien synchronisieren (alte l<>schen, neue hinzuf<75>gen) >>
|
||||
existingProduct.Productcategories.Clear();
|
||||
foreach (var categorieId in productDto.categorieIds)
|
||||
{
|
||||
existingProduct.Productcategories.Add(new Productcategorie { ProductId = existingProduct.Id, categorieId = categorieId });
|
||||
}
|
||||
// << ENDE NEUER TEIL >>
|
||||
|
||||
await _productRepository.UpdateProductAsync(existingProduct); // << KORREKT: VERWENDET UpdateProductAsync >>
|
||||
await _productRepository.UpdateProductAsync(existingProduct);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -157,7 +186,7 @@ namespace Webshop.Application.Services.Admin
|
||||
var product = await _productRepository.GetProductByIdAsync(id);
|
||||
if (product == null) return false;
|
||||
|
||||
await _productRepository.DeleteProductAsync(id); // << KORREKT: VERWENDET DeleteProductAsync >>
|
||||
await _productRepository.DeleteProductAsync(id);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// src/Webshop.Application/Services/Admin/IAdminProductService.cs
|
||||
// src/Webshop.Application/Services/Admin/Interfaces/IAdminProductService.cs
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Webshop.Application.DTOs.Products;
|
||||
@@ -9,8 +9,8 @@ namespace Webshop.Application.Services.Admin.Interfaces
|
||||
{
|
||||
Task<IEnumerable<AdminProductDto>> GetAllAdminProductsAsync();
|
||||
Task<AdminProductDto?> GetAdminProductByIdAsync(Guid id);
|
||||
Task<AdminProductDto> CreateAdminProductAsync(AdminProductDto productDto);
|
||||
Task<bool> UpdateAdminProductAsync(AdminProductDto productDto);
|
||||
Task<AdminProductDto> CreateAdminProductAsync(CreateAdminProductDto productDto); // << NEUER TYP >>
|
||||
Task<bool> UpdateAdminProductAsync(UpdateAdminProductDto productDto); // << NEUER TYP >>
|
||||
Task<bool> DeleteAdminProductAsync(Guid id);
|
||||
}
|
||||
}
|
||||
@@ -1,44 +1,40 @@
|
||||
// src/Webshop.Application/Services/Public/ProductService.cs
|
||||
using Microsoft.EntityFrameworkCore; // << NEU: Für Include() und ThenInclude() >>
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Webshop.Application.DTOs.Categorie; // Für categorieDto
|
||||
using Webshop.Application.DTOs.Products; // Für ProductDto
|
||||
using Webshop.Application.Services.Public.Interfaces; // Für IProductService
|
||||
using Webshop.Domain.Interfaces; // Für IProductRepository
|
||||
using Webshop.Infrastructure.Data; // << NEU: Für ApplicationDbContext >>
|
||||
using Webshop.Application.DTOs.Categorie;
|
||||
using Webshop.Application.DTOs.Products;
|
||||
using Webshop.Application.Services.Public.Interfaces;
|
||||
using Webshop.Domain.Interfaces;
|
||||
using Webshop.Infrastructure.Data;
|
||||
|
||||
namespace Webshop.Application.Services.Public
|
||||
{
|
||||
public class ProductService : IProductService
|
||||
{
|
||||
private readonly IProductRepository _productRepository;
|
||||
private readonly ApplicationDbContext _context; // << NEU: Für direkten DB-Zugriff >>
|
||||
private readonly ApplicationDbContext _context;
|
||||
|
||||
public ProductService(IProductRepository productRepository, ApplicationDbContext context) // << NEU: DbContext injizieren >>
|
||||
public ProductService(ApplicationDbContext context)
|
||||
{
|
||||
_productRepository = productRepository;
|
||||
_context = context; // << NEU >>
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<ProductDto>> GetAllProductsAsync()
|
||||
{
|
||||
// Wir verwenden den DbContext, um Produkte und ihre Kategorien zu laden
|
||||
var products = await _context.Products
|
||||
.Include(p => p.Productcategories) // Lade die Join-Tabelle
|
||||
.ThenInclude(pc => pc.categorie) // Lade die zugehörige Kategorie-Entität
|
||||
.Where(p => p.IsActive) // Nur aktive Produkte
|
||||
.Include(p => p.Productcategories).ThenInclude(pc => pc.categorie)
|
||||
.Include(p => p.Images) // Lade Bilder mit
|
||||
.Where(p => p.IsActive)
|
||||
.ToListAsync();
|
||||
|
||||
return products.Select(p => new ProductDto
|
||||
{
|
||||
Id = p.Id,
|
||||
Name = p.Name,
|
||||
Description = p.ShortDescription, // Oder p.Description, je nach Anforderung
|
||||
Description = p.ShortDescription,
|
||||
Price = p.Price,
|
||||
SKU = p.SKU,
|
||||
ImageUrl = p.ImageUrl,
|
||||
IsInStock = p.IsInStock,
|
||||
Slug = p.Slug,
|
||||
categories = p.Productcategories.Select(pc => new CategorieDto
|
||||
@@ -46,7 +42,13 @@ namespace Webshop.Application.Services.Public
|
||||
Id = pc.categorie.Id,
|
||||
Name = pc.categorie.Name,
|
||||
Slug = pc.categorie.Slug
|
||||
// ... weitere categorieDto-Felder bei Bedarf
|
||||
}).ToList(),
|
||||
Images = p.Images.Select(img => new ProductImageDto
|
||||
{
|
||||
Id = img.Id,
|
||||
Url = img.Url,
|
||||
IsMainImage = img.IsMainImage,
|
||||
DisplayOrder = img.DisplayOrder
|
||||
}).ToList()
|
||||
}).ToList();
|
||||
}
|
||||
@@ -54,9 +56,9 @@ namespace Webshop.Application.Services.Public
|
||||
public async Task<ProductDto?> GetProductBySlugAsync(string slug)
|
||||
{
|
||||
var product = await _context.Products
|
||||
.Include(p => p.Productcategories)
|
||||
.ThenInclude(pc => pc.categorie)
|
||||
.FirstOrDefaultAsync(p => p.Slug == slug && p.IsActive); // Nur aktives Produkt finden
|
||||
.Include(p => p.Productcategories).ThenInclude(pc => pc.categorie)
|
||||
.Include(p => p.Images) // Lade Bilder mit
|
||||
.FirstOrDefaultAsync(p => p.Slug == slug && p.IsActive);
|
||||
|
||||
if (product == null)
|
||||
{
|
||||
@@ -67,10 +69,9 @@ namespace Webshop.Application.Services.Public
|
||||
{
|
||||
Id = product.Id,
|
||||
Name = product.Name,
|
||||
Description = product.Description, // Hier die volle Beschreibung
|
||||
Description = product.Description,
|
||||
Price = product.Price,
|
||||
SKU = product.SKU,
|
||||
ImageUrl = product.ImageUrl,
|
||||
IsInStock = product.IsInStock,
|
||||
Slug = product.Slug,
|
||||
categories = product.Productcategories.Select(pc => new CategorieDto
|
||||
@@ -78,6 +79,13 @@ namespace Webshop.Application.Services.Public
|
||||
Id = pc.categorie.Id,
|
||||
Name = pc.categorie.Name,
|
||||
Slug = pc.categorie.Slug
|
||||
}).ToList(),
|
||||
Images = product.Images.Select(img => new ProductImageDto
|
||||
{
|
||||
Id = img.Id,
|
||||
Url = img.Url,
|
||||
IsMainImage = img.IsMainImage,
|
||||
DisplayOrder = img.DisplayOrder
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user