103 lines
2.4 KiB
C#
103 lines
2.4 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 TelefonoRepo : ITelefonoRepo
|
|
{
|
|
|
|
|
|
private readonly RECHUMAContext _Context;
|
|
|
|
public TelefonoRepo(RECHUMAContext Context)
|
|
{
|
|
_Context = Context;
|
|
}
|
|
|
|
public async Task<IEnumerable<Telefono>> GetTelefonos()
|
|
{
|
|
try
|
|
{
|
|
var telefonos = await _Context.Telefono.AsNoTracking().ToListAsync();
|
|
return telefonos;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
|
|
throw;
|
|
}
|
|
}
|
|
|
|
public async Task<Telefono> GetTelefono(int IdTelefono)
|
|
{
|
|
try
|
|
{
|
|
var telefono = await _Context.Telefono.FirstOrDefaultAsync(s => s.IdTelefono == IdTelefono);
|
|
return telefono;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
|
|
throw;
|
|
}
|
|
}
|
|
|
|
public async Task<bool> PutTelefono(Telefono telefono)
|
|
{
|
|
try
|
|
{
|
|
var telefonoctual = await GetTelefono(telefono.IdTelefono);
|
|
|
|
telefonoctual.Numero = telefono.Numero;
|
|
//bancoActual.Estado = banco.Estado;
|
|
|
|
int rows = await _Context.SaveChangesAsync();
|
|
return rows > 0;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
|
|
throw;
|
|
}
|
|
}
|
|
|
|
public async Task PostTelefono(Telefono telefono)
|
|
{
|
|
try
|
|
{
|
|
_Context.Telefono.Add(telefono);
|
|
await _Context.SaveChangesAsync();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
|
|
throw;
|
|
}
|
|
}
|
|
|
|
public async Task<bool> DeleteTelefono(int IdTelefono)
|
|
{
|
|
try
|
|
{
|
|
var telefonoActual = await GetTelefono(IdTelefono);
|
|
_Context.Telefono.Remove(telefonoActual);
|
|
|
|
int rows = await _Context.SaveChangesAsync();
|
|
return rows > 0;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
|
|
throw;
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|