try
This commit is contained in:
@@ -1,13 +1,15 @@
|
||||
// src/Webshop.Infrastructure/Repositories/CustomerRepository.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 CustomerRepository : ICustomerRepository
|
||||
public class CustomerRepository : ICustomerRepository // MUSS public sein
|
||||
{
|
||||
private readonly ApplicationDbContext _context;
|
||||
|
||||
@@ -16,15 +18,17 @@ namespace Webshop.Infrastructure.Repositories
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<Customer?> GetByUserIdAsync(string userId)
|
||||
{
|
||||
return await _context.Customers.FirstOrDefaultAsync(c => c.AspNetUserId == userId);
|
||||
}
|
||||
// Beispiel-Implementierungen (wenn nicht schon vorhanden):
|
||||
public async Task<IEnumerable<Customer>> GetAllAsync() => await _context.Customers.ToListAsync();
|
||||
public async Task<Customer?> GetByIdAsync(Guid id) => await _context.Customers.FindAsync(id);
|
||||
public async Task AddAsync(Customer entity) { _context.Customers.Add(entity); await _context.SaveChangesAsync(); }
|
||||
public async Task UpdateAsync(Customer entity) { _context.Customers.Update(entity); await _context.SaveChangesAsync(); }
|
||||
public async Task DeleteAsync(Guid id) { var entity = await _context.Customers.FindAsync(id); if (entity != null) { _context.Customers.Remove(entity); await _context.SaveChangesAsync(); } }
|
||||
|
||||
public async Task UpdateAsync(Customer customer)
|
||||
// KORREKTE IMPLEMENTIERUNG F<>R GetByUserIdAsync
|
||||
public async Task<Customer?> GetByUserIdAsync(string aspNetUserId)
|
||||
{
|
||||
_context.Customers.Update(customer);
|
||||
await _context.SaveChangesAsync();
|
||||
return await _context.Customers.FirstOrDefaultAsync(c => c.AspNetUserId == aspNetUserId);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,15 @@
|
||||
// src/Webshop.Infrastructure/Repositories/SupplierRepository.cs
|
||||
// Auto-generiert von CreateWebshopFiles.ps1 (aktualisiert um Implementierungen)
|
||||
using Microsoft.EntityFrameworkCore; // Wichtig für ToListAsync, FindAsync etc.
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Webshop.Domain.Entities;
|
||||
using Webshop.Domain.Interfaces;
|
||||
using Webshop.Infrastructure.Data;
|
||||
using System; // Für Guid
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Webshop.Infrastructure.Repositories
|
||||
{
|
||||
public class SupplierRepository : ISupplierRepository // Hier muss das Interface stehen
|
||||
public class SupplierRepository : ISupplierRepository // MUSS public sein
|
||||
{
|
||||
private readonly ApplicationDbContext _context;
|
||||
|
||||
@@ -19,8 +18,6 @@ namespace Webshop.Infrastructure.Repositories
|
||||
_context = context;
|
||||
}
|
||||
|
||||
// --- IMPLEMENTIERUNG DER ISupplierRepository METHODEN ---
|
||||
|
||||
public async Task<IEnumerable<Supplier>> GetAllSuppliersAsync()
|
||||
{
|
||||
return await _context.Suppliers.ToListAsync();
|
||||
@@ -34,7 +31,7 @@ namespace Webshop.Infrastructure.Repositories
|
||||
public async Task AddSupplierAsync(Supplier supplier)
|
||||
{
|
||||
_context.Suppliers.Add(supplier);
|
||||
await _context.SaveChangesAsync(); // Änderungen in der DB speichern
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public async Task UpdateSupplierAsync(Supplier supplier)
|
||||
@@ -45,11 +42,11 @@ namespace Webshop.Infrastructure.Repositories
|
||||
|
||||
public async Task DeleteSupplierAsync(Guid id)
|
||||
{
|
||||
var supplier = await _context.Suppliers.FindAsync(id); // Lieferant zuerst finden
|
||||
var supplier = await _context.Suppliers.FindAsync(id);
|
||||
if (supplier != null)
|
||||
{
|
||||
_context.Suppliers.Remove(supplier); // Lieferant entfernen
|
||||
await _context.SaveChangesAsync(); // Änderungen speichern
|
||||
_context.Suppliers.Remove(supplier);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user