// src/Webshop.Infrastructure/Repositories/SupplierRepository.cs // Auto-generiert von CreateWebshopFiles.ps1 (aktualisiert um Implementierungen) using Microsoft.EntityFrameworkCore; // Wichtig für ToListAsync, FindAsync etc. using Webshop.Domain.Entities; using Webshop.Domain.Interfaces; using Webshop.Infrastructure.Data; using System; // Für Guid using System.Collections.Generic; using System.Threading.Tasks; namespace Webshop.Infrastructure.Repositories { public class SupplierRepository : ISupplierRepository // Hier muss das Interface stehen { private readonly ApplicationDbContext _context; public SupplierRepository(ApplicationDbContext context) { _context = context; } // --- IMPLEMENTIERUNG DER ISupplierRepository METHODEN --- public async Task> GetAllSuppliersAsync() { return await _context.Suppliers.ToListAsync(); } public async Task GetSupplierByIdAsync(Guid id) { return await _context.Suppliers.FindAsync(id); } public async Task AddSupplierAsync(Supplier supplier) { _context.Suppliers.Add(supplier); await _context.SaveChangesAsync(); // Änderungen in der DB speichern } public async Task UpdateSupplierAsync(Supplier supplier) { _context.Suppliers.Update(supplier); await _context.SaveChangesAsync(); } public async Task DeleteSupplierAsync(Guid id) { var supplier = await _context.Suppliers.FindAsync(id); // Lieferant zuerst finden if (supplier != null) { _context.Suppliers.Remove(supplier); // Lieferant entfernen await _context.SaveChangesAsync(); // Änderungen speichern } } } }