categorys
This commit is contained in:
@@ -1,18 +1,129 @@
|
||||
// Auto-generiert von CreateWebshopFiles.ps1
|
||||
// src/Webshop.Application/Services/Admin/AdminCategoryService.cs
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Webshop.Application.Services.Admin.Interfaces;
|
||||
|
||||
using Webshop.Application.DTOs.Categorys;
|
||||
using Webshop.Domain.Entities;
|
||||
using Webshop.Domain.Interfaces;
|
||||
|
||||
namespace Webshop.Application.Services.Admin
|
||||
{
|
||||
public class AdminCategoryService : IAdminCategoryService
|
||||
{
|
||||
// Fügen Sie hier Abhängigkeiten per Dependency Injection hinzu (z.B. Repositories)
|
||||
private readonly ICategoryRepository _categoryRepository;
|
||||
|
||||
// public AdminCategoryService(IYourRepository repository) { }
|
||||
public AdminCategoryService(ICategoryRepository categoryRepository)
|
||||
{
|
||||
_categoryRepository = categoryRepository;
|
||||
}
|
||||
|
||||
// Fügen Sie hier Service-Methoden hinzu
|
||||
public async Task<IEnumerable<CategoryDto>> GetAllAsync()
|
||||
{
|
||||
var categories = await _categoryRepository.GetAllAsync();
|
||||
return categories.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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,17 @@
|
||||
// Auto-generiert von CreateWebshopFiles.ps1
|
||||
// src/Webshop.Application/Services/Admin/IAdminCategoryService.cs
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Webshop.Application.DTOs;
|
||||
using Webshop.Application.DTOs.Auth;
|
||||
using Webshop.Application.DTOs.Users;
|
||||
using Webshop.Application.DTOs.Categorys;
|
||||
|
||||
|
||||
namespace Webshop.Application.Services.Admin.Interfaces
|
||||
namespace Webshop.Application.Services.Admin
|
||||
{
|
||||
public interface IAdminCategoryService
|
||||
{
|
||||
// Fügen Sie hier Methodensignaturen hinzu
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,57 @@
|
||||
// Auto-generiert von CreateWebshopFiles.ps1
|
||||
using System;
|
||||
// src/Webshop.Application/Services/Public/CategoryService.cs
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Webshop.Application.Services.Public.Interfaces;
|
||||
|
||||
using Webshop.Application.DTOs.Categorys;
|
||||
using Webshop.Domain.Interfaces;
|
||||
|
||||
namespace Webshop.Application.Services.Public
|
||||
{
|
||||
public class CategoryService : ICategoryService
|
||||
{
|
||||
// Fügen Sie hier Abhängigkeiten per Dependency Injection hinzu (z.B. Repositories)
|
||||
private readonly ICategoryRepository _categoryRepository;
|
||||
|
||||
// public CategoryService(IYourRepository repository) { }
|
||||
public CategoryService(ICategoryRepository categoryRepository)
|
||||
{
|
||||
_categoryRepository = categoryRepository;
|
||||
}
|
||||
|
||||
// Fügen Sie hier Service-Methoden hinzu
|
||||
public async Task<IEnumerable<CategoryDto>> GetAllActiveAsync()
|
||||
{
|
||||
var categories = await _categoryRepository.GetAllAsync();
|
||||
|
||||
// Hier könnte man eine Baumstruktur aufbauen, für den Anfang eine flache Liste
|
||||
return categories
|
||||
.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
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,13 @@
|
||||
// Auto-generiert von CreateWebshopFiles.ps1
|
||||
using System;
|
||||
// src/Webshop.Application/Services/Public/ICategoryService.cs
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Webshop.Application.DTOs;
|
||||
using Webshop.Application.DTOs.Auth;
|
||||
using Webshop.Application.DTOs.Users;
|
||||
using Webshop.Application.DTOs.Categorys;
|
||||
|
||||
|
||||
namespace Webshop.Application.Services.Public.Interfaces
|
||||
namespace Webshop.Application.Services.Public
|
||||
{
|
||||
public interface ICategoryService
|
||||
{
|
||||
// Fügen Sie hier Methodensignaturen hinzu
|
||||
Task<IEnumerable<CategoryDto>> GetAllActiveAsync();
|
||||
Task<CategoryDto?> GetBySlugAsync(string slug);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user