using Microsoft.EntityFrameworkCore; using REC_HUMA.CORE.Entities; using REC_HUMA.CORE.Interfaces; using REC_HUMA.INFRASTRUCTURE; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace REC_HUMA.INFRASTRUCTURE.Repositories { public class EmpresaRepo : IEmpresaRepo { private readonly RECHUMAContext _Context; public EmpresaRepo(RECHUMAContext Context) { _Context = Context; } public async Task> GetEmpresas() { try { var empresas = await _Context.Empresa.AsNoTracking().ToListAsync(); return empresas; } catch (Exception ex) { throw; } } public async Task GetEmpresa(int IdEmpresa) { try { var empresa = await _Context.Empresa.Where(s => s.IdEmpresa == IdEmpresa).FirstOrDefaultAsync(); return empresa; } catch (Exception ex) { throw; } } public async Task PutEmpresa(Empresa empresa) { try { _Context.Empresa.Update(empresa); await _Context.SaveChangesAsync(); } catch (Exception ex) { throw; } } public async Task PostEmpresa(Empresa empresa) { try { _Context.Empresa.Add(empresa); await _Context.SaveChangesAsync(); } catch (Exception ex) { throw; } } public async Task DeleteEmpresa(int IdEmpresa) { try { var empresa = _Context.Empresa.Where(s => s.IdEmpresa == IdEmpresa).FirstOrDefault(); _Context.Empresa.Remove(empresa); await _Context.SaveChangesAsync(); } catch (Exception ex) { throw; } } } }