34 lines
1.5 KiB
C#
34 lines
1.5 KiB
C#
// 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 // MUSS public sein
|
|
{
|
|
private readonly ApplicationDbContext _context;
|
|
|
|
public CustomerRepository(ApplicationDbContext context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
// 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(); } }
|
|
|
|
// KORREKTE IMPLEMENTIERUNG FÜR GetByUserIdAsync
|
|
public async Task<Customer?> GetByUserIdAsync(string aspNetUserId)
|
|
{
|
|
return await _context.Customers.FirstOrDefaultAsync(c => c.AspNetUserId == aspNetUserId);
|
|
}
|
|
}
|
|
} |