85 lines
2.1 KiB
C#
85 lines
2.1 KiB
C#
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 BeneficioRepo : IBeneficioRepo
|
|
{
|
|
private readonly RECHUMAContext _Context;
|
|
public BeneficioRepo(RECHUMAContext Context)
|
|
{
|
|
_Context = Context;
|
|
}
|
|
public async Task<IEnumerable<Beneficio>> GetBeneficios()
|
|
{
|
|
try
|
|
{
|
|
var beneficios = await _Context.Beneficio.AsNoTracking().ToListAsync();
|
|
return beneficios;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
|
|
throw;
|
|
}
|
|
}
|
|
|
|
public async Task<Beneficio> GetBeneficio(int IdBeneficio)
|
|
{
|
|
try
|
|
{
|
|
var beneficio = await _Context.Beneficio.Where(s => s.IdBeneficio == IdBeneficio).FirstOrDefaultAsync();
|
|
return beneficio;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
|
|
throw;
|
|
}
|
|
}
|
|
|
|
public async Task PutBeneficio(Beneficio beneficio)
|
|
{
|
|
try
|
|
{
|
|
_Context.Beneficio.Update(beneficio);
|
|
await _Context.SaveChangesAsync();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
|
|
throw;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
public async Task PostBeneficio(Beneficio beneficio)
|
|
{
|
|
await _Context.Beneficio.AddAsync(beneficio);
|
|
_Context.SaveChanges();
|
|
|
|
}
|
|
public async Task DeleteBeneficio(int IdBeneficio)
|
|
{
|
|
try
|
|
{
|
|
var beneficio = _Context.Beneficio.Where(s => s.IdBeneficio == IdBeneficio).FirstOrDefault();
|
|
_Context.Beneficio.Remove(beneficio);
|
|
await _Context.SaveChangesAsync();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
|
|
throw;
|
|
}
|
|
}
|
|
}
|
|
}
|