naming
This commit is contained in:
129
Webshop.Application/Services/Admin/AdminCategorieService.cs
Normal file
129
Webshop.Application/Services/Admin/AdminCategorieService.cs
Normal file
@@ -0,0 +1,129 @@
|
||||
// src/Webshop.Application/Services/Admin/Admincategorieservice.cs
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Webshop.Application.DTOs.categories;
|
||||
using Webshop.Domain.Entities;
|
||||
using Webshop.Domain.Interfaces;
|
||||
|
||||
namespace Webshop.Application.Services.Admin
|
||||
{
|
||||
public class AdminCategorieService : IAdminCategorieService
|
||||
{
|
||||
private readonly IcategorieRepository _categorieRepository;
|
||||
|
||||
public AdminCategorieService(IcategorieRepository categorieRepository)
|
||||
{
|
||||
_categorieRepository = categorieRepository;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<categorieDto>> GetAllAsync()
|
||||
{
|
||||
var categories = await _categorieRepository.GetAllAsync();
|
||||
return categories.Select(c => new categorieDto
|
||||
{
|
||||
Id = c.Id,
|
||||
Name = c.Name,
|
||||
Slug = c.Slug,
|
||||
Description = c.Description,
|
||||
ParentcategorieId = c.ParentcategorieId,
|
||||
ImageUrl = c.ImageUrl,
|
||||
IsActive = c.IsActive,
|
||||
DisplayOrder = c.DisplayOrder
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
public async Task<categorieDto?> GetByIdAsync(Guid id)
|
||||
{
|
||||
var categorie = await _categorieRepository.GetByIdAsync(id);
|
||||
if (categorie == null) return null;
|
||||
|
||||
return new categorieDto
|
||||
{
|
||||
Id = categorie.Id,
|
||||
Name = categorie.Name,
|
||||
Slug = categorie.Slug,
|
||||
Description = categorie.Description,
|
||||
ParentcategorieId = categorie.ParentcategorieId,
|
||||
ImageUrl = categorie.ImageUrl,
|
||||
IsActive = categorie.IsActive,
|
||||
DisplayOrder = categorie.DisplayOrder
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<(categorieDto? Createdcategorie, string? ErrorMessage)> CreateAsync(CreatecategorieDto categorieDto)
|
||||
{
|
||||
var existingcategorie = await _categorieRepository.GetBySlugAsync(categorieDto.Slug);
|
||||
if (existingcategorie != null)
|
||||
{
|
||||
return (null, "Eine Kategorie mit diesem Slug existiert bereits.");
|
||||
}
|
||||
|
||||
var categorie = new categorie
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
Name = categorieDto.Name,
|
||||
Slug = categorieDto.Slug,
|
||||
Description = categorieDto.Description,
|
||||
ParentcategorieId = categorieDto.ParentcategorieId,
|
||||
ImageUrl = categorieDto.ImageUrl,
|
||||
IsActive = categorieDto.IsActive,
|
||||
DisplayOrder = categorieDto.DisplayOrder,
|
||||
CreatedDate = DateTimeOffset.UtcNow
|
||||
};
|
||||
|
||||
await _categorieRepository.AddAsync(categorie);
|
||||
|
||||
var createdDto = new categorieDto
|
||||
{
|
||||
Id = categorie.Id,
|
||||
Name = categorie.Name,
|
||||
Slug = categorie.Slug,
|
||||
Description = categorie.Description,
|
||||
ParentcategorieId = categorie.ParentcategorieId,
|
||||
ImageUrl = categorie.ImageUrl,
|
||||
IsActive = categorie.IsActive,
|
||||
DisplayOrder = categorie.DisplayOrder
|
||||
};
|
||||
|
||||
return (createdDto, null);
|
||||
}
|
||||
|
||||
public async Task<(bool Success, string? ErrorMessage)> UpdateAsync(Guid id, CreatecategorieDto categorieDto)
|
||||
{
|
||||
var existingcategorie = await _categorieRepository.GetByIdAsync(id);
|
||||
if (existingcategorie == null)
|
||||
{
|
||||
return (false, "Kategorie nicht gefunden.");
|
||||
}
|
||||
|
||||
var categorieWithSameSlug = await _categorieRepository.GetBySlugAsync(categorieDto.Slug);
|
||||
if (categorieWithSameSlug != null && categorieWithSameSlug.Id != id)
|
||||
{
|
||||
return (false, "Eine andere Kategorie mit diesem Slug existiert bereits.");
|
||||
}
|
||||
|
||||
existingcategorie.Name = categorieDto.Name;
|
||||
existingcategorie.Slug = categorieDto.Slug;
|
||||
existingcategorie.Description = categorieDto.Description;
|
||||
existingcategorie.ParentcategorieId = categorieDto.ParentcategorieId;
|
||||
existingcategorie.ImageUrl = categorieDto.ImageUrl;
|
||||
existingcategorie.IsActive = categorieDto.IsActive;
|
||||
existingcategorie.DisplayOrder = categorieDto.DisplayOrder;
|
||||
existingcategorie.LastModifiedDate = DateTimeOffset.UtcNow;
|
||||
|
||||
await _categorieRepository.UpdateAsync(existingcategorie);
|
||||
return (true, null);
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteAsync(Guid id)
|
||||
{
|
||||
var categorie = await _categorieRepository.GetByIdAsync(id);
|
||||
if (categorie == null) return false;
|
||||
|
||||
await _categorieRepository.DeleteAsync(id);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,129 +0,0 @@
|
||||
// src/Webshop.Application/Services/Admin/AdminCategoryService.cs
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Webshop.Application.DTOs.Categorys;
|
||||
using Webshop.Domain.Entities;
|
||||
using Webshop.Domain.Interfaces;
|
||||
|
||||
namespace Webshop.Application.Services.Admin
|
||||
{
|
||||
public class AdminCategoryService : IAdminCategoryService
|
||||
{
|
||||
private readonly ICategoryRepository _categoryRepository;
|
||||
|
||||
public AdminCategoryService(ICategoryRepository categoryRepository)
|
||||
{
|
||||
_categoryRepository = categoryRepository;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<CategoryDto>> GetAllAsync()
|
||||
{
|
||||
var categorys = await _categoryRepository.GetAllAsync();
|
||||
return categorys.Select(c => new CategoryDto
|
||||
{
|
||||
Id = c.Id,
|
||||
Name = c.Name,
|
||||
Slug = c.Slug,
|
||||
Description = c.Description,
|
||||
ParentCategoryId = c.ParentCategoryId,
|
||||
ImageUrl = c.ImageUrl,
|
||||
IsActive = c.IsActive,
|
||||
DisplayOrder = c.DisplayOrder
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
public async Task<CategoryDto?> GetByIdAsync(Guid id)
|
||||
{
|
||||
var category = await _categoryRepository.GetByIdAsync(id);
|
||||
if (category == null) return null;
|
||||
|
||||
return new CategoryDto
|
||||
{
|
||||
Id = category.Id,
|
||||
Name = category.Name,
|
||||
Slug = category.Slug,
|
||||
Description = category.Description,
|
||||
ParentCategoryId = category.ParentCategoryId,
|
||||
ImageUrl = category.ImageUrl,
|
||||
IsActive = category.IsActive,
|
||||
DisplayOrder = category.DisplayOrder
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<(CategoryDto? CreatedCategory, string? ErrorMessage)> CreateAsync(CreateCategoryDto categoryDto)
|
||||
{
|
||||
var existingCategory = await _categoryRepository.GetBySlugAsync(categoryDto.Slug);
|
||||
if (existingCategory != null)
|
||||
{
|
||||
return (null, "Eine Kategorie mit diesem Slug existiert bereits.");
|
||||
}
|
||||
|
||||
var category = new Category
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
Name = categoryDto.Name,
|
||||
Slug = categoryDto.Slug,
|
||||
Description = categoryDto.Description,
|
||||
ParentCategoryId = categoryDto.ParentCategoryId,
|
||||
ImageUrl = categoryDto.ImageUrl,
|
||||
IsActive = categoryDto.IsActive,
|
||||
DisplayOrder = categoryDto.DisplayOrder,
|
||||
CreatedDate = DateTimeOffset.UtcNow
|
||||
};
|
||||
|
||||
await _categoryRepository.AddAsync(category);
|
||||
|
||||
var createdDto = new CategoryDto
|
||||
{
|
||||
Id = category.Id,
|
||||
Name = category.Name,
|
||||
Slug = category.Slug,
|
||||
Description = category.Description,
|
||||
ParentCategoryId = category.ParentCategoryId,
|
||||
ImageUrl = category.ImageUrl,
|
||||
IsActive = category.IsActive,
|
||||
DisplayOrder = category.DisplayOrder
|
||||
};
|
||||
|
||||
return (createdDto, null);
|
||||
}
|
||||
|
||||
public async Task<(bool Success, string? ErrorMessage)> UpdateAsync(Guid id, CreateCategoryDto categoryDto)
|
||||
{
|
||||
var existingCategory = await _categoryRepository.GetByIdAsync(id);
|
||||
if (existingCategory == null)
|
||||
{
|
||||
return (false, "Kategorie nicht gefunden.");
|
||||
}
|
||||
|
||||
var categoryWithSameSlug = await _categoryRepository.GetBySlugAsync(categoryDto.Slug);
|
||||
if (categoryWithSameSlug != null && categoryWithSameSlug.Id != id)
|
||||
{
|
||||
return (false, "Eine andere Kategorie mit diesem Slug existiert bereits.");
|
||||
}
|
||||
|
||||
existingCategory.Name = categoryDto.Name;
|
||||
existingCategory.Slug = categoryDto.Slug;
|
||||
existingCategory.Description = categoryDto.Description;
|
||||
existingCategory.ParentCategoryId = categoryDto.ParentCategoryId;
|
||||
existingCategory.ImageUrl = categoryDto.ImageUrl;
|
||||
existingCategory.IsActive = categoryDto.IsActive;
|
||||
existingCategory.DisplayOrder = categoryDto.DisplayOrder;
|
||||
existingCategory.LastModifiedDate = DateTimeOffset.UtcNow;
|
||||
|
||||
await _categoryRepository.UpdateAsync(existingCategory);
|
||||
return (true, null);
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteAsync(Guid id)
|
||||
{
|
||||
var category = await _categoryRepository.GetByIdAsync(id);
|
||||
if (category == null) return false;
|
||||
|
||||
await _categoryRepository.DeleteAsync(id);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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.Productcategorys)
|
||||
.Include(p => p.Productcategories)
|
||||
.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.Productcategorys.Select(pc => pc.CategoryId).ToList() // << NEU >>
|
||||
categorieIds = p.Productcategories.Select(pc => pc.categorieId).ToList() // << NEU >>
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
public async Task<AdminProductDto?> GetAdminProductByIdAsync(Guid id)
|
||||
{
|
||||
var product = await _context.Products
|
||||
.Include(p => p.Productcategorys) // << NEU: Lade die Join-Tabelle mit >>
|
||||
.Include(p => p.Productcategories) // << 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.Productcategorys.Select(pc => pc.CategoryId).ToList() // << NEU: Mappe die CategoryIds >>
|
||||
categorieIds = product.Productcategories.Select(pc => pc.categorieId).ToList() // << NEU: Mappe die categorieIds >>
|
||||
};
|
||||
}
|
||||
|
||||
@@ -101,13 +101,13 @@ namespace Webshop.Application.Services.Admin
|
||||
CreatedDate = DateTimeOffset.UtcNow,
|
||||
SupplierId = productDto.SupplierId,
|
||||
PurchasePrice = productDto.PurchasePrice,
|
||||
Productcategorys = new List<ProductCategory>() // Initialisiere die Collection
|
||||
Productcategories = new List<Productcategorie>() // Initialisiere die Collection
|
||||
};
|
||||
|
||||
// << NEU: F<>ge die Kategorien hinzu >>
|
||||
foreach (var categoryId in productDto.CategoryIds)
|
||||
foreach (var categorieId in productDto.categorieIds)
|
||||
{
|
||||
newProduct.Productcategorys.Add(new ProductCategory { CategoryId = categoryId });
|
||||
newProduct.Productcategories.Add(new Productcategorie { categorieId = categorieId });
|
||||
}
|
||||
|
||||
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.Productcategorys) // Lade die aktuellen Zuweisungen
|
||||
.Include(p => p.Productcategories) // 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.Productcategorys.Clear();
|
||||
foreach (var categoryId in productDto.CategoryIds)
|
||||
existingProduct.Productcategories.Clear();
|
||||
foreach (var categorieId in productDto.categorieIds)
|
||||
{
|
||||
existingProduct.Productcategorys.Add(new ProductCategory { ProductId = existingProduct.Id, CategoryId = categoryId });
|
||||
existingProduct.Productcategories.Add(new Productcategorie { ProductId = existingProduct.Id, categorieId = categorieId });
|
||||
}
|
||||
// << ENDE NEUER TEIL >>
|
||||
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
// src/Webshop.Application/Services/Admin/IAdmincategorieservice.cs
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Webshop.Application.DTOs.categories;
|
||||
|
||||
namespace Webshop.Application.Services.Admin
|
||||
{
|
||||
public interface IAdminCategorieService
|
||||
{
|
||||
Task<IEnumerable<categorieDto>> GetAllAsync();
|
||||
Task<categorieDto?> GetByIdAsync(Guid id);
|
||||
Task<(categorieDto? Createdcategorie, string? ErrorMessage)> CreateAsync(CreatecategorieDto categorieDto);
|
||||
Task<(bool Success, string? ErrorMessage)> UpdateAsync(Guid id, CreatecategorieDto categorieDto);
|
||||
Task<bool> DeleteAsync(Guid id);
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
// src/Webshop.Application/Services/Admin/IAdminCategoryService.cs
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Webshop.Application.DTOs.Categorys;
|
||||
|
||||
namespace Webshop.Application.Services.Admin
|
||||
{
|
||||
public interface IAdminCategoryService
|
||||
{
|
||||
Task<IEnumerable<CategoryDto>> GetAllAsync();
|
||||
Task<CategoryDto?> GetByIdAsync(Guid id);
|
||||
Task<(CategoryDto? CreatedCategory, string? ErrorMessage)> CreateAsync(CreateCategoryDto categoryDto);
|
||||
Task<(bool Success, string? ErrorMessage)> UpdateAsync(Guid id, CreateCategoryDto categoryDto);
|
||||
Task<bool> DeleteAsync(Guid id);
|
||||
}
|
||||
}
|
||||
57
Webshop.Application/Services/Public/CategorieService.cs
Normal file
57
Webshop.Application/Services/Public/CategorieService.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
// src/Webshop.Application/Services/Public/categorieservice.cs
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Webshop.Application.DTOs.categories;
|
||||
using Webshop.Domain.Interfaces;
|
||||
|
||||
namespace Webshop.Application.Services.Public
|
||||
{
|
||||
public class CategorieService : ICategorieService
|
||||
{
|
||||
private readonly IcategorieRepository _categorieRepository;
|
||||
|
||||
public CategorieService(IcategorieRepository categorieRepository)
|
||||
{
|
||||
_categorieRepository = categorieRepository;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<categorieDto>> GetAllActiveAsync()
|
||||
{
|
||||
var categories = await _categorieRepository.GetAllAsync();
|
||||
|
||||
// Hier könnte man eine Baumstruktur aufbauen, für den Anfang eine flache Liste
|
||||
return categories
|
||||
.Where(c => c.IsActive)
|
||||
.Select(c => new categorieDto
|
||||
{
|
||||
Id = c.Id,
|
||||
Name = c.Name,
|
||||
Slug = c.Slug,
|
||||
Description = c.Description,
|
||||
ParentcategorieId = c.ParentcategorieId,
|
||||
ImageUrl = c.ImageUrl,
|
||||
IsActive = c.IsActive,
|
||||
DisplayOrder = c.DisplayOrder
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
public async Task<categorieDto?> GetBySlugAsync(string slug)
|
||||
{
|
||||
var categorie = await _categorieRepository.GetBySlugAsync(slug);
|
||||
if (categorie == null || !categorie.IsActive) return null;
|
||||
|
||||
return new categorieDto
|
||||
{
|
||||
Id = categorie.Id,
|
||||
Name = categorie.Name,
|
||||
Slug = categorie.Slug,
|
||||
Description = categorie.Description,
|
||||
ParentcategorieId = categorie.ParentcategorieId,
|
||||
ImageUrl = categorie.ImageUrl,
|
||||
IsActive = categorie.IsActive,
|
||||
DisplayOrder = categorie.DisplayOrder
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
// src/Webshop.Application/Services/Public/CategoryService.cs
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Webshop.Application.DTOs.Categorys;
|
||||
using Webshop.Domain.Interfaces;
|
||||
|
||||
namespace Webshop.Application.Services.Public
|
||||
{
|
||||
public class CategoryService : ICategoryService
|
||||
{
|
||||
private readonly ICategoryRepository _categoryRepository;
|
||||
|
||||
public CategoryService(ICategoryRepository categoryRepository)
|
||||
{
|
||||
_categoryRepository = categoryRepository;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<CategoryDto>> GetAllActiveAsync()
|
||||
{
|
||||
var categorys = await _categoryRepository.GetAllAsync();
|
||||
|
||||
// Hier könnte man eine Baumstruktur aufbauen, für den Anfang eine flache Liste
|
||||
return categorys
|
||||
.Where(c => c.IsActive)
|
||||
.Select(c => new CategoryDto
|
||||
{
|
||||
Id = c.Id,
|
||||
Name = c.Name,
|
||||
Slug = c.Slug,
|
||||
Description = c.Description,
|
||||
ParentCategoryId = c.ParentCategoryId,
|
||||
ImageUrl = c.ImageUrl,
|
||||
IsActive = c.IsActive,
|
||||
DisplayOrder = c.DisplayOrder
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
public async Task<CategoryDto?> GetBySlugAsync(string slug)
|
||||
{
|
||||
var category = await _categoryRepository.GetBySlugAsync(slug);
|
||||
if (category == null || !category.IsActive) return null;
|
||||
|
||||
return new CategoryDto
|
||||
{
|
||||
Id = category.Id,
|
||||
Name = category.Name,
|
||||
Slug = category.Slug,
|
||||
Description = category.Description,
|
||||
ParentCategoryId = category.ParentCategoryId,
|
||||
ImageUrl = category.ImageUrl,
|
||||
IsActive = category.IsActive,
|
||||
DisplayOrder = category.DisplayOrder
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// src/Webshop.Application/Services/Public/Icategorieservice.cs
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Webshop.Application.DTOs.categories;
|
||||
|
||||
namespace Webshop.Application.Services.Public
|
||||
{
|
||||
public interface ICategorieService
|
||||
{
|
||||
Task<IEnumerable<categorieDto>> GetAllActiveAsync();
|
||||
Task<categorieDto?> GetBySlugAsync(string slug);
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
// src/Webshop.Application/Services/Public/ICategoryService.cs
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Webshop.Application.DTOs.Categorys;
|
||||
|
||||
namespace Webshop.Application.Services.Public
|
||||
{
|
||||
public interface ICategoryService
|
||||
{
|
||||
Task<IEnumerable<CategoryDto>> GetAllActiveAsync();
|
||||
Task<CategoryDto?> GetBySlugAsync(string slug);
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ using Microsoft.EntityFrameworkCore; // << NEU: Für Include() und ThenInclude()
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Webshop.Application.DTOs.Categorys; // Für CategoryDto
|
||||
using Webshop.Application.DTOs.categories; // 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
|
||||
@@ -26,8 +26,8 @@ namespace Webshop.Application.Services.Public
|
||||
{
|
||||
// Wir verwenden den DbContext, um Produkte und ihre Kategorien zu laden
|
||||
var products = await _context.Products
|
||||
.Include(p => p.Productcategorys) // Lade die Join-Tabelle
|
||||
.ThenInclude(pc => pc.Category) // Lade die zugehörige Kategorie-Entität
|
||||
.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
|
||||
.ToListAsync();
|
||||
|
||||
@@ -41,12 +41,12 @@ namespace Webshop.Application.Services.Public
|
||||
ImageUrl = p.ImageUrl,
|
||||
IsInStock = p.IsInStock,
|
||||
Slug = p.Slug,
|
||||
categorys = p.Productcategorys.Select(pc => new CategoryDto
|
||||
categories = p.Productcategories.Select(pc => new categorieDto
|
||||
{
|
||||
Id = pc.Category.Id,
|
||||
Name = pc.Category.Name,
|
||||
Slug = pc.Category.Slug
|
||||
// ... weitere CategoryDto-Felder bei Bedarf
|
||||
Id = pc.categorie.Id,
|
||||
Name = pc.categorie.Name,
|
||||
Slug = pc.categorie.Slug
|
||||
// ... weitere categorieDto-Felder bei Bedarf
|
||||
}).ToList()
|
||||
}).ToList();
|
||||
}
|
||||
@@ -54,8 +54,8 @@ namespace Webshop.Application.Services.Public
|
||||
public async Task<ProductDto?> GetProductBySlugAsync(string slug)
|
||||
{
|
||||
var product = await _context.Products
|
||||
.Include(p => p.Productcategorys)
|
||||
.ThenInclude(pc => pc.Category)
|
||||
.Include(p => p.Productcategories)
|
||||
.ThenInclude(pc => pc.categorie)
|
||||
.FirstOrDefaultAsync(p => p.Slug == slug && p.IsActive); // Nur aktives Produkt finden
|
||||
|
||||
if (product == null)
|
||||
@@ -73,11 +73,11 @@ namespace Webshop.Application.Services.Public
|
||||
ImageUrl = product.ImageUrl,
|
||||
IsInStock = product.IsInStock,
|
||||
Slug = product.Slug,
|
||||
categorys = product.Productcategorys.Select(pc => new CategoryDto
|
||||
categories = product.Productcategories.Select(pc => new categorieDto
|
||||
{
|
||||
Id = pc.Category.Id,
|
||||
Name = pc.Category.Name,
|
||||
Slug = pc.Category.Slug
|
||||
Id = pc.categorie.Id,
|
||||
Name = pc.categorie.Name,
|
||||
Slug = pc.categorie.Slug
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user