// src/Webshop.Infrastructure/Repositories/ProductRepository.cs using Microsoft.EntityFrameworkCore; using Webshop.Domain.Entities; using Webshop.Domain.Interfaces; using Webshop.Infrastructure.Data; namespace Webshop.Infrastructure.Repositories { public class ProductRepository : IProductRepository { private readonly ApplicationDbContext _context; // Wir lassen uns den DbContext per Dependency Injection geben public ProductRepository(ApplicationDbContext context) { _context = context; } public async Task> GetAllProductsAsync() { return await _context.Products.ToListAsync(); } public async Task GetProductByIdAsync(Guid id) { return await _context.Products.FindAsync(id); } public async Task AddProductAsync(Product product) { _context.Products.Add(product); await _context.SaveChangesAsync(); // Wichtig: Änderungen speichern } public async Task UpdateProductAsync(Product product) { _context.Products.Update(product); await _context.SaveChangesAsync(); } public async Task DeleteProductAsync(Guid id) { var product = await _context.Products.FindAsync(id); if (product != null) { _context.Products.Remove(product); await _context.SaveChangesAsync(); } } } }