Projektdateien hinzufügen.

This commit is contained in:
Webtree-design
2025-07-21 20:17:52 +02:00
parent b5367c704f
commit 16d38a8f39
44 changed files with 4613 additions and 0 deletions

View File

@@ -0,0 +1,51 @@
// 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<IEnumerable<Product>> GetAllProductsAsync()
{
return await _context.Products.ToListAsync();
}
public async Task<Product?> 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();
}
}
}
}