33 lines
1010 B
C#
33 lines
1010 B
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using WinWARP.Core.Data;
|
|
using WinWARP.Core.Models.Entities;
|
|
using WinWARP.Core.Services.Interfaces;
|
|
|
|
namespace WinWARP.Core.Services.Implementations;
|
|
|
|
public class SubscriptionDbService : ISubscriptionDbService
|
|
{
|
|
private readonly IDbContextFactory<AppDbContext> _dbContextFactory;
|
|
|
|
public SubscriptionDbService(IDbContextFactory<AppDbContext> dbContextFactory)
|
|
{
|
|
_dbContextFactory = dbContextFactory;
|
|
}
|
|
|
|
public async Task<List<Subscription>> GetSubscriptionsAsync()
|
|
{
|
|
using var dbContext = await _dbContextFactory.CreateDbContextAsync();
|
|
return await dbContext.Subscriptions.ToListAsync();
|
|
}
|
|
|
|
public async Task AddSubscriptionAsync(Subscription subscription)
|
|
{
|
|
using var dbContext = await _dbContextFactory.CreateDbContextAsync();
|
|
dbContext.Subscriptions.Add(subscription);
|
|
await dbContext.SaveChangesAsync();
|
|
}
|
|
}
|