All checks were successful
CI/CD Pipeline / Build and Deploy with Docker Compose (push) Successful in 2m56s
44 lines
961 B
C#
44 lines
961 B
C#
using Microsoft.EntityFrameworkCore;
|
|
using Models.Interfaces;
|
|
|
|
namespace Models.Repositories
|
|
{
|
|
public class GenericRepository<T> : IGenericRepository<T> where T : class
|
|
{
|
|
private readonly DbContext _context;
|
|
private readonly DbSet<T> _dbSet;
|
|
|
|
public GenericRepository(DbContext context)
|
|
{
|
|
_context = context;
|
|
_dbSet = _context.Set<T>();
|
|
}
|
|
|
|
public async Task<T?> GetByIdAsync(int id)
|
|
{
|
|
return await _dbSet.FindAsync(id);
|
|
}
|
|
|
|
public async Task<IEnumerable<T>> GetAllAsync()
|
|
{
|
|
return await _dbSet.ToListAsync();
|
|
}
|
|
|
|
public async Task AddAsync(T entity)
|
|
{
|
|
await _dbSet.AddAsync(entity);
|
|
}
|
|
|
|
public void Update(T entity)
|
|
{
|
|
_dbSet.Update(entity);
|
|
}
|
|
|
|
public void Delete(T entity)
|
|
{
|
|
_dbSet.Remove(entity);
|
|
}
|
|
}
|
|
|
|
}
|