Files
ShopSolution-backend/Webshop.Infrastructure/Repositories/SupplierRepository.cs
Tizian.Breuch c1ee56c81c try
2025-07-29 14:04:35 +02:00

53 lines
1.5 KiB
C#

// src/Webshop.Infrastructure/Repositories/SupplierRepository.cs
using Microsoft.EntityFrameworkCore;
using Webshop.Domain.Entities;
using Webshop.Domain.Interfaces;
using Webshop.Infrastructure.Data;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Webshop.Infrastructure.Repositories
{
public class SupplierRepository : ISupplierRepository // MUSS public sein
{
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();
}
}
}
}