supplier und migration
This commit is contained in:
@@ -12,8 +12,8 @@ using Webshop.Infrastructure.Data;
|
||||
namespace Webshop.Infrastructure.Migrations
|
||||
{
|
||||
[DbContext(typeof(ApplicationDbContext))]
|
||||
[Migration("20250723094917_InitialCreate")]
|
||||
partial class InitialCreate
|
||||
[Migration("20250723102855_AddSuppliersAndOtherEntities")]
|
||||
partial class AddSuppliersAndOtherEntities
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
@@ -7,7 +7,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
namespace Webshop.Infrastructure.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class InitialCreate : Migration
|
||||
public partial class AddSuppliersAndOtherEntities : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
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