Files
ShopSolution-backend/Webshop.Infrastructure/Repositories/ShippingMethodRepository.cs
2025-08-01 09:09:49 +02:00

27 lines
1.3 KiB
C#

// src/Webshop.Infrastructure/Repositories/ShippingMethodRepository.cs
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Webshop.Domain.Entities;
using Webshop.Domain.Interfaces;
using Webshop.Infrastructure.Data;
namespace Webshop.Infrastructure.Repositories
{
public class ShippingMethodRepository : IShippingMethodRepository
{
private readonly ApplicationDbContext _context;
public ShippingMethodRepository(ApplicationDbContext context)
{
_context = context;
}
public async Task<IEnumerable<ShippingMethod>> GetAllAsync() => await _context.ShippingMethods.ToListAsync();
public async Task<ShippingMethod?> GetByIdAsync(Guid id) => await _context.ShippingMethods.FindAsync(id);
public async Task AddAsync(ShippingMethod shippingMethod) { _context.ShippingMethods.Add(shippingMethod); await _context.SaveChangesAsync(); }
public async Task UpdateAsync(ShippingMethod shippingMethod) { _context.ShippingMethods.Update(shippingMethod); await _context.SaveChangesAsync(); }
public async Task DeleteAsync(Guid id) { var entity = await _context.ShippingMethods.FindAsync(id); if (entity != null) { _context.ShippingMethods.Remove(entity); await _context.SaveChangesAsync(); } }
}
}