66 lines
2.2 KiB
C#
66 lines
2.2 KiB
C#
|
|
using Microsoft.EntityFrameworkCore;
|
||
|
|
using GestorFacturas.API.Models;
|
||
|
|
namespace GestorFacturas.API.Data;
|
||
|
|
|
||
|
|
public class ApplicationDbContext : DbContext
|
||
|
|
{
|
||
|
|
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
|
||
|
|
: base(options)
|
||
|
|
{
|
||
|
|
}
|
||
|
|
public DbSet<Configuracion> Configuraciones { get; set; }
|
||
|
|
public DbSet<Evento> Eventos { get; set; }
|
||
|
|
public DbSet<Usuario> Usuarios { get; set; }
|
||
|
|
public DbSet<RefreshToken> RefreshTokens { get; set; }
|
||
|
|
|
||
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||
|
|
{
|
||
|
|
base.OnModelCreating(modelBuilder);
|
||
|
|
|
||
|
|
modelBuilder.Entity<Configuracion>(entity =>
|
||
|
|
{
|
||
|
|
entity.ToTable("Configuraciones");
|
||
|
|
entity.HasData(new Configuracion
|
||
|
|
{
|
||
|
|
Id = 1,
|
||
|
|
Periodicidad = "Dias",
|
||
|
|
ValorPeriodicidad = 1,
|
||
|
|
HoraEjecucion = "00:00:00",
|
||
|
|
Estado = true,
|
||
|
|
EnEjecucion = false,
|
||
|
|
DBServidor = "TECNICA3",
|
||
|
|
DBNombre = "",
|
||
|
|
DBTrusted = true,
|
||
|
|
RutaFacturas = "",
|
||
|
|
RutaDestino = "",
|
||
|
|
SMTPPuerto = 587,
|
||
|
|
SMTPSSL = true,
|
||
|
|
AvisoMail = false
|
||
|
|
});
|
||
|
|
});
|
||
|
|
|
||
|
|
modelBuilder.Entity<Evento>(entity =>
|
||
|
|
{
|
||
|
|
entity.ToTable("Eventos");
|
||
|
|
entity.HasIndex(e => e.Fecha);
|
||
|
|
entity.HasIndex(e => e.Tipo);
|
||
|
|
});
|
||
|
|
|
||
|
|
// Seed de Usuario Admin
|
||
|
|
// Pass: admin123
|
||
|
|
modelBuilder.Entity<Usuario>().HasData(new Usuario
|
||
|
|
{
|
||
|
|
Id = 1,
|
||
|
|
Username = "admin",
|
||
|
|
Nombre = "Administrador",
|
||
|
|
PasswordHash = "$2a$11$l5UnZIE8bVWSUhYorVqlW.f0qgvK2zsD8aYDyTRXKjtFwwdiAfAvW" // Hash placeholder, se actualiza al loguear si es necesario o usar uno real
|
||
|
|
});
|
||
|
|
|
||
|
|
// Configuración de RefreshToken (Opcional si usas convenciones, pero bueno para ser explícito)
|
||
|
|
modelBuilder.Entity<Usuario>()
|
||
|
|
.HasMany<RefreshToken>()
|
||
|
|
.WithOne(r => r.Usuario)
|
||
|
|
.HasForeignKey(r => r.UsuarioId)
|
||
|
|
.OnDelete(DeleteBehavior.Cascade);
|
||
|
|
}
|
||
|
|
}
|