// src/Webshop.Application/Services/Admin/AdminSettingService.cs using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Webshop.Application.DTOs.Settings; using Webshop.Application.Services.Admin.Interfaces; using Webshop.Domain.Interfaces; namespace Webshop.Application.Services.Admin { public class AdminSettingService : IAdminSettingService { private readonly ISettingRepository _settingRepository; public AdminSettingService(ISettingRepository settingRepository) { _settingRepository = settingRepository; } public async Task>> GetAllGroupedAsync() { var settings = await _settingRepository.GetAllAsync(); return settings .GroupBy(s => s.Group ?? "Uncategorized") .ToDictionary( g => g.Key, g => g.Select(s => new SettingDto { Key = s.Key, Value = s.Value, Description = s.Description, IsActive = s.IsActive, Group = s.Group }).ToList() ); } public async Task UpdateSettingsAsync(List settings) { foreach (var settingDto in settings) { var setting = await _settingRepository.GetByKeyAsync(settingDto.Key); if (setting != null) { setting.Value = settingDto.Value; setting.IsActive = settingDto.IsActive; // Auch IsActive aktualisieren await _settingRepository.UpdateAsync(setting); } } } } }