Files
ShopSolution-backend/Webshop.Infrastructure/Repositories/SupplierRepository.cs
2025-07-23 12:33:01 +02:00

50 lines
1.4 KiB
C#

// src/Webshop.Infrastructure/Repositories/SupplierRepository.cs
using Microsoft.EntityFrameworkCore; // Für ToListAsync
using Webshop.Domain.Entities;
using Webshop.Domain.Interfaces;
using Webshop.Infrastructure.Data;
namespace Webshop.Infrastructure.Repositories
{
public class SupplierRepository : ISupplierRepository
{
private readonly ApplicationDbContext _context;
public SupplierRepository(ApplicationDbContext context)
{
_context = context;
}
public async Task<IEnumerable<Supplier>> GetAllSuppliersAsync()
{
return await _context.Suppliers.ToListAsync();
}
public async Task<Supplier?> GetSupplierByIdAsync(Guid id)
{
return await _context.Suppliers.FindAsync(id);
}
public async Task AddSupplierAsync(Supplier supplier)
{
_context.Suppliers.Add(supplier);
await _context.SaveChangesAsync();
}
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);
if (supplier != null)
{
_context.Suppliers.Remove(supplier);
await _context.SaveChangesAsync();
}
}
}
}