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

94 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 CantonRepo : ICantonRepo
{
private readonly RECHUMAContext _Context;
public CantonRepo(RECHUMAContext Context)
{
_Context = Context;
}
public async Task<IEnumerable<Canton>> GetCantones()
{
try
{
var cantones = await _Context.Canton.AsNoTracking().ToListAsync();
return cantones;
}
catch (Exception ex)
{
throw;
}
}
public async Task<Canton> GetCanton(int IdCanton)
{
try
{
var canton = await _Context.Canton.Where(s => s.IdCanton == IdCanton).FirstOrDefaultAsync();
return canton;
}
catch (Exception ex)
{
throw;
}
}
public async Task PutCanton(Canton canton)
{
try
{
_Context.Canton.Update(canton);
await _Context.SaveChangesAsync();
}
catch (Exception ex)
{
throw;
}
}
public async Task PostCanton(Canton canton)
{
try
{
await _Context.Canton.AddAsync(canton);
_Context.SaveChanges();
}
catch (Exception)
{
throw;
}
}
public async Task DeleteCanton(int IdCanton)
{
try
{
var canton = _Context.Canton.Where(s => s.IdCanton == IdCanton).FirstOrDefault();
_Context.Canton.Remove(canton);
await _Context.SaveChangesAsync();
}
catch (Exception ex)
{
throw;
}
}
}
}