43 lines
1.3 KiB
C#
43 lines
1.3 KiB
C#
// src/Webshop.Infrastructure/Repositories/SettingRepository.cs
|
|
using Microsoft.EntityFrameworkCore;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using Webshop.Domain.Entities;
|
|
using Webshop.Domain.Interfaces;
|
|
using Webshop.Infrastructure.Data;
|
|
|
|
namespace Webshop.Infrastructure.Repositories
|
|
{
|
|
// Implementiert die reinen Datenbankoperationen
|
|
public class SettingRepository : ISettingRepository
|
|
{
|
|
private readonly ApplicationDbContext _context;
|
|
|
|
public SettingRepository(ApplicationDbContext context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
public async Task<IEnumerable<Setting>> GetAllAsync()
|
|
{
|
|
return await _context.Settings.OrderBy(s => s.Group).ThenBy(s => s.Key).ToListAsync();
|
|
}
|
|
|
|
public async Task<Setting?> GetByKeyAsync(string key)
|
|
{
|
|
return await _context.Settings.FirstOrDefaultAsync(s => s.Key == key);
|
|
}
|
|
|
|
public async Task AddAsync(Setting setting)
|
|
{
|
|
await _context.Settings.AddAsync(setting);
|
|
await _context.SaveChangesAsync();
|
|
}
|
|
|
|
public async Task UpdateAsync(Setting setting)
|
|
{
|
|
_context.Settings.Update(setting);
|
|
await _context.SaveChangesAsync();
|
|
}
|
|
}
|
|
} |