using FlowAPI.Application.Interfaces; using FlowAPI.Infrastructure.Data; using Microsoft.EntityFrameworkCore; namespace FlowAPI.Infrastructure.Repositories { public class GenericRepository : IGenericRepository where T : class { protected readonly AppDbContext _context; protected readonly DbSet _dbSet; public GenericRepository(AppDbContext context) { _context = context; _dbSet = context.Set(); } public virtual async Task> GetAllAsync() { return await _dbSet.AsNoTracking().ToListAsync(); } public virtual async Task GetByIdAsync(Guid id) { return await _dbSet.FindAsync(id); } public virtual async Task CreateAsync(T entity) { _dbSet.Add(entity); await _context.SaveChangesAsync(); return entity; } public virtual async Task UpdateAsync(T entity) { _dbSet.Update(entity); await _context.SaveChangesAsync(); return entity; } public virtual async Task DeleteAsync(Guid id) { var entity = await _dbSet.FindAsync(id); if (entity is null) return false; _dbSet.Remove(entity); await _context.SaveChangesAsync(); return true; } } }