This commit is contained in:
Tizian.Breuch
2025-08-01 10:06:00 +02:00
parent 8a4590ee5a
commit 6f86d0de87
15 changed files with 79 additions and 79 deletions

View File

@@ -20,8 +20,8 @@ namespace Webshop.Application.Services.Admin
public async Task<IEnumerable<CategoryDto>> GetAllAsync()
{
var categories = await _categoryRepository.GetAllAsync();
return categories.Select(c => new CategoryDto
var categorys = await _categoryRepository.GetAllAsync();
return categorys.Select(c => new CategoryDto
{
Id = c.Id,
Name = c.Name,

View File

@@ -27,7 +27,7 @@ namespace Webshop.Application.Services.Admin
{
// Wir verwenden den DbContext, um auch die Kategorien effizient mitzuladen
var products = await _context.Products
.Include(p => p.ProductCategories)
.Include(p => p.Productcategorys)
.ToListAsync();
return products.Select(p => new AdminProductDto
@@ -48,14 +48,14 @@ namespace Webshop.Application.Services.Admin
LastModifiedDate = p.LastModifiedDate,
SupplierId = p.SupplierId,
PurchasePrice = p.PurchasePrice,
CategoryIds = p.ProductCategories.Select(pc => pc.CategoryId).ToList() // << NEU >>
CategoryIds = p.Productcategorys.Select(pc => pc.CategoryId).ToList() // << NEU >>
}).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.Productcategorys) // << NEU: Lade die Join-Tabelle mit >>
.FirstOrDefaultAsync(p => p.Id == id);
if (product == null) return null;
@@ -78,7 +78,7 @@ namespace Webshop.Application.Services.Admin
LastModifiedDate = product.LastModifiedDate,
SupplierId = product.SupplierId,
PurchasePrice = product.PurchasePrice,
CategoryIds = product.ProductCategories.Select(pc => pc.CategoryId).ToList() // << NEU: Mappe die CategoryIds >>
CategoryIds = product.Productcategorys.Select(pc => pc.CategoryId).ToList() // << NEU: Mappe die CategoryIds >>
};
}
@@ -101,13 +101,13 @@ namespace Webshop.Application.Services.Admin
CreatedDate = DateTimeOffset.UtcNow,
SupplierId = productDto.SupplierId,
PurchasePrice = productDto.PurchasePrice,
ProductCategories = new List<ProductCategory>() // Initialisiere die Collection
Productcategorys = new List<ProductCategory>() // Initialisiere die Collection
};
// << NEU: F<>ge die Kategorien hinzu >>
foreach (var categoryId in productDto.CategoryIds)
{
newProduct.ProductCategories.Add(new ProductCategory { CategoryId = categoryId });
newProduct.Productcategorys.Add(new ProductCategory { CategoryId = categoryId });
}
await _productRepository.AddProductAsync(newProduct); // << KORREKT: VERWENDET AddProductAsync >>
@@ -119,7 +119,7 @@ namespace Webshop.Application.Services.Admin
public async Task<bool> UpdateAdminProductAsync(AdminProductDto productDto)
{
var existingProduct = await _context.Products
.Include(p => p.ProductCategories) // Lade die aktuellen Zuweisungen
.Include(p => p.Productcategorys) // Lade die aktuellen Zuweisungen
.FirstOrDefaultAsync(p => p.Id == productDto.Id);
if (existingProduct == null) return false;
@@ -141,10 +141,10 @@ namespace Webshop.Application.Services.Admin
existingProduct.LastModifiedDate = DateTimeOffset.UtcNow;
// << NEU: Kategorien synchronisieren (alte l<>schen, neue hinzuf<75>gen) >>
existingProduct.ProductCategories.Clear();
existingProduct.Productcategorys.Clear();
foreach (var categoryId in productDto.CategoryIds)
{
existingProduct.ProductCategories.Add(new ProductCategory { ProductId = existingProduct.Id, CategoryId = categoryId });
existingProduct.Productcategorys.Add(new ProductCategory { ProductId = existingProduct.Id, CategoryId = categoryId });
}
// << ENDE NEUER TEIL >>