TFS_ANTIGUO/TPAtesa_RecHuma/REC-HUMA.INFRASTRUCTURE/Repositories/DistritoRepo.cs
2026-06-26 10:14:39 -06:00

94 lines
2.2 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 DistritoRepo : IDistritoRepo
{
private readonly RECHUMAContext _Context;
public DistritoRepo(RECHUMAContext Context)
{
_Context = Context;
}
public async Task<IEnumerable<Distrito>> GetDistritos()
{
try
{
var distritos = await _Context.Distrito.AsNoTracking().ToListAsync();
return distritos;
}
catch (Exception ex)
{
throw;
}
}
public async Task<Distrito> GetDistrito(int IdDistrito)
{
try
{
var distrito = await _Context.Distrito.Where(s => s.IdDistrito == IdDistrito).FirstOrDefaultAsync();
return distrito;
}
catch (Exception ex)
{
throw;
}
}
public async Task PutDistrito(Distrito distrito)
{
try
{
_Context.Distrito.Update(distrito);
await _Context.SaveChangesAsync();
}
catch (Exception ex)
{
throw;
}
}
public async Task PostDistrito(Distrito distrito)
{
try
{
_Context.Distrito.Add(distrito);
await _Context.SaveChangesAsync();
}
catch (Exception ex)
{
throw;
}
}
public async Task DeleteDistrito(int IdDistrito)
{
try
{
var distrito = _Context.Distrito.Where(s => s.IdDistrito == IdDistrito).FirstOrDefault();
_Context.Distrito.Remove(distrito);
await _Context.SaveChangesAsync();
}
catch (Exception ex)
{
throw;
}
}
}
}