naming
This commit is contained in:
@@ -19,6 +19,6 @@ namespace Webshop.Application.DTOs.Products
|
||||
public int StockQuantity { get; set; }
|
||||
public string? ImageUrl { get; set; }
|
||||
public string Slug { get; set; } = string.Empty;
|
||||
public List<CategoryDto> Categories { get; set; } = new List<CategoryDto>();
|
||||
public List<CategoryDto> categorys { get; set; } = new List<CategoryDto>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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 >>
|
||||
|
||||
|
||||
@@ -18,10 +18,10 @@ namespace Webshop.Application.Services.Public
|
||||
|
||||
public async Task<IEnumerable<CategoryDto>> GetAllActiveAsync()
|
||||
{
|
||||
var categories = await _categoryRepository.GetAllAsync();
|
||||
var categorys = await _categoryRepository.GetAllAsync();
|
||||
|
||||
// Hier könnte man eine Baumstruktur aufbauen, für den Anfang eine flache Liste
|
||||
return categories
|
||||
return categorys
|
||||
.Where(c => c.IsActive)
|
||||
.Select(c => new CategoryDto
|
||||
{
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace Webshop.Application.Services.Public
|
||||
{
|
||||
// Wir verwenden den DbContext, um Produkte und ihre Kategorien zu laden
|
||||
var products = await _context.Products
|
||||
.Include(p => p.ProductCategories) // Lade die Join-Tabelle
|
||||
.Include(p => p.Productcategorys) // Lade die Join-Tabelle
|
||||
.ThenInclude(pc => pc.Category) // Lade die zugehörige Kategorie-Entität
|
||||
.Where(p => p.IsActive) // Nur aktive Produkte
|
||||
.ToListAsync();
|
||||
@@ -41,7 +41,7 @@ namespace Webshop.Application.Services.Public
|
||||
ImageUrl = p.ImageUrl,
|
||||
IsInStock = p.IsInStock,
|
||||
Slug = p.Slug,
|
||||
Categories = p.ProductCategories.Select(pc => new CategoryDto
|
||||
categorys = p.Productcategorys.Select(pc => new CategoryDto
|
||||
{
|
||||
Id = pc.Category.Id,
|
||||
Name = pc.Category.Name,
|
||||
@@ -54,7 +54,7 @@ namespace Webshop.Application.Services.Public
|
||||
public async Task<ProductDto?> GetProductBySlugAsync(string slug)
|
||||
{
|
||||
var product = await _context.Products
|
||||
.Include(p => p.ProductCategories)
|
||||
.Include(p => p.Productcategorys)
|
||||
.ThenInclude(pc => pc.Category)
|
||||
.FirstOrDefaultAsync(p => p.Slug == slug && p.IsActive); // Nur aktives Produkt finden
|
||||
|
||||
@@ -73,7 +73,7 @@ namespace Webshop.Application.Services.Public
|
||||
ImageUrl = product.ImageUrl,
|
||||
IsInStock = product.IsInStock,
|
||||
Slug = product.Slug,
|
||||
Categories = product.ProductCategories.Select(pc => new CategoryDto
|
||||
categorys = product.Productcategorys.Select(pc => new CategoryDto
|
||||
{
|
||||
Id = pc.Category.Id,
|
||||
Name = pc.Category.Name,
|
||||
|
||||
Reference in New Issue
Block a user