Initial Commit
Inital Commit of Code base, nothing tested.
This commit is contained in:
commit
0144221712
31 changed files with 1304 additions and 0 deletions
35
FreeTubeSync/Repository.cs
Normal file
35
FreeTubeSync/Repository.cs
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
using FreeTubeSync.Database;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace FreeTubeSync;
|
||||
|
||||
public class Repository<TEntity>(DataContext dbContext) : IRepository<TEntity> where TEntity : class
|
||||
{
|
||||
public async Task AddAsync(TEntity entity, CancellationToken ct)
|
||||
{
|
||||
dbContext.Set<TEntity>().Add(entity);
|
||||
await dbContext.SaveChangesAsync(ct);
|
||||
}
|
||||
|
||||
public async Task UpdateAsync(TEntity entity, CancellationToken ct)
|
||||
{
|
||||
dbContext.Set<TEntity>().Update(entity);
|
||||
await dbContext.SaveChangesAsync(ct);
|
||||
}
|
||||
|
||||
public async Task DeleteAsync(TEntity entity, CancellationToken ct)
|
||||
{
|
||||
dbContext.Set<TEntity>().Remove(entity);
|
||||
await dbContext.SaveChangesAsync(ct);
|
||||
}
|
||||
|
||||
public async Task<TEntity?> GetByIdAsync(string id, CancellationToken ct)
|
||||
{
|
||||
return await dbContext.Set<TEntity>().FindAsync(id, ct);
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<TEntity>> GetAllAsync(CancellationToken ct)
|
||||
{
|
||||
return await dbContext.Set<TEntity>().ToListAsync<TEntity>(ct);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue