phronCare/Models/Repositories/GenericRepository.cs
Leandro Hernan Rojas a44f321652
All checks were successful
CI/CD Pipeline / Build and Deploy with Docker Compose (push) Successful in 3m46s
Add Patch 3 in API
2025-04-03 19:08:33 -03:00

45 lines
1022 B
C#

using Microsoft.EntityFrameworkCore;
using Models.Interfaces;
using Models.Models;
namespace Models.Repositories
{
public class GenericRepository<T> : IGenericRepository<T> where T : class
{
private readonly PhronCareOperationsHubContext _context;
private readonly DbSet<T> _dbSet;
public GenericRepository(PhronCareOperationsHubContext 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);
}
}
}