85 lines
3.1 KiB
C#
85 lines
3.1 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using line_gestao_api.Models;
|
|
|
|
namespace line_gestao_api.Data;
|
|
|
|
public class AppDbContext : DbContext
|
|
{
|
|
public AppDbContext(DbContextOptions<AppDbContext> options) : base(options) { }
|
|
|
|
public DbSet<User> Users => Set<User>();
|
|
|
|
// ✅ tabela para espelhar a planilha (GERAL)
|
|
public DbSet<MobileLine> MobileLines => Set<MobileLine>();
|
|
|
|
// ✅ tabela para espelhar a aba MUREG
|
|
public DbSet<MuregLine> MuregLines => Set<MuregLine>();
|
|
|
|
// ✅ tabela para espelhar o FATURAMENTO (PF/PJ)
|
|
public DbSet<BillingClient> BillingClients => Set<BillingClient>();
|
|
|
|
public DbSet<UserData> UserDatas => Set<UserData>();
|
|
|
|
public DbSet<VigenciaLine> VigenciaLines { get; set; } = default!;
|
|
|
|
public DbSet<TrocaNumeroLine> TrocaNumeroLines => Set<TrocaNumeroLine>();
|
|
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
{
|
|
base.OnModelCreating(modelBuilder);
|
|
|
|
// =========================
|
|
// ✅ USER
|
|
// =========================
|
|
modelBuilder.Entity<User>()
|
|
.HasIndex(u => u.Email)
|
|
.IsUnique();
|
|
|
|
// =========================
|
|
// ✅ GERAL (MobileLine)
|
|
// =========================
|
|
modelBuilder.Entity<MobileLine>()
|
|
.HasIndex(x => x.Linha)
|
|
.IsUnique();
|
|
|
|
// =========================
|
|
// ✅ MUREG
|
|
// =========================
|
|
modelBuilder.Entity<MuregLine>().HasIndex(x => x.Item);
|
|
modelBuilder.Entity<MuregLine>().HasIndex(x => x.Cliente);
|
|
modelBuilder.Entity<MuregLine>().HasIndex(x => x.ICCID);
|
|
modelBuilder.Entity<MuregLine>().HasIndex(x => x.LinhaNova);
|
|
|
|
// ==========================================================
|
|
// ✅ FATURAMENTO (BillingClient) - mantém seu mapeamento
|
|
// ==========================================================
|
|
modelBuilder.Entity<BillingClient>(e =>
|
|
{
|
|
e.ToTable("billing_clients");
|
|
|
|
e.HasKey(x => x.Id);
|
|
|
|
e.Property(x => x.Tipo).HasMaxLength(2);
|
|
e.Property(x => x.Cliente).HasMaxLength(255);
|
|
|
|
e.HasIndex(x => x.Tipo);
|
|
e.HasIndex(x => x.Cliente);
|
|
e.HasIndex(x => new { x.Tipo, x.Cliente });
|
|
e.HasIndex(x => x.Item);
|
|
});
|
|
|
|
// ==========================================================
|
|
// ✅ VIGÊNCIA (se você quiser índices aqui também, pode manter)
|
|
// ==========================================================
|
|
// modelBuilder.Entity<VigenciaLine>().HasIndex(x => x.Cliente);
|
|
// modelBuilder.Entity<VigenciaLine>().HasIndex(x => x.Linha);
|
|
|
|
// ==========================================================
|
|
// ✅ TROCA NÚMERO (opcional: índices)
|
|
// ==========================================================
|
|
// modelBuilder.Entity<TrocaNumeroLine>().HasIndex(x => x.Cliente);
|
|
// modelBuilder.Entity<TrocaNumeroLine>().HasIndex(x => x.LinhaAntiga);
|
|
// modelBuilder.Entity<TrocaNumeroLine>().HasIndex(x => x.LinhaNova);
|
|
}
|
|
}
|