supplier und migration
This commit is contained in:
50
Webshop.Infrastructure/Repositories/SupplierRepository.cs
Normal file
50
Webshop.Infrastructure/Repositories/SupplierRepository.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
// 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user