Files
Tizian.Breuch 6fc6aaef3e payment
2025-07-29 19:11:34 +02:00

27 lines
1.3 KiB
C#

// src/Webshop.Infrastructure/Repositories/PaymentMethodRepository.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 PaymentMethodRepository : IPaymentMethodRepository
{
private readonly ApplicationDbContext _context;
public PaymentMethodRepository(ApplicationDbContext context)
{
_context = context;
}
public async Task<IEnumerable<PaymentMethod>> GetAllAsync() => await _context.PaymentMethods.ToListAsync();
public async Task<PaymentMethod?> GetByIdAsync(Guid id) => await _context.PaymentMethods.FindAsync(id);
public async Task AddAsync(PaymentMethod paymentMethod) { _context.PaymentMethods.Add(paymentMethod); await _context.SaveChangesAsync(); }
public async Task UpdateAsync(PaymentMethod paymentMethod) { _context.PaymentMethods.Update(paymentMethod); await _context.SaveChangesAsync(); }
public async Task DeleteAsync(Guid id) { var entity = await _context.PaymentMethods.FindAsync(id); if (entity != null) { _context.PaymentMethods.Remove(entity); await _context.SaveChangesAsync(); } }
}
}