52 lines
1.5 KiB
C#
52 lines
1.5 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using Asistencia.Models;
|
|
|
|
namespace Asistencia.Data.Repositories;
|
|
|
|
public class ProfesorRepository
|
|
{
|
|
private readonly AppDbContext _context;
|
|
|
|
public ProfesorRepository(AppDbContext context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
public async Task<Profesor?> BuscarPorRutAsync(string rut)
|
|
{
|
|
return await _context.Profesores.FirstOrDefaultAsync(p => p.RutPasaporte == rut);
|
|
}
|
|
|
|
public async Task<bool> ActualizarClaveAsync(string rut, string nuevaClave)
|
|
{
|
|
var profesor = await _context.Profesores.FirstOrDefaultAsync(p => p.RutPasaporte == rut);
|
|
if (profesor == null) return false;
|
|
|
|
profesor.Clave = nuevaClave;
|
|
profesor.CrearClave = false;
|
|
await _context.SaveChangesAsync();
|
|
return true;
|
|
}
|
|
|
|
public async Task<bool> ActualizarEmailAsync(string rut, string email)
|
|
{
|
|
var profesor = await _context.Profesores.FirstOrDefaultAsync(p => p.RutPasaporte == rut);
|
|
if (profesor == null) return false;
|
|
|
|
profesor.Email = email;
|
|
await _context.SaveChangesAsync();
|
|
return true;
|
|
}
|
|
|
|
public async Task<Profesor?> AutenticarAsync(string rut, string clave)
|
|
{
|
|
var profesor = await _context.Profesores.FirstOrDefaultAsync(p => p.RutPasaporte == rut);
|
|
if (profesor == null) return null;
|
|
|
|
if (profesor.CrearClave) return null;
|
|
|
|
var claveDescifrada = Helpers.CryptoHelper.Desencriptar(profesor.Clave);
|
|
return claveDescifrada == clave ? profesor : null;
|
|
}
|
|
}
|