using IUT_ISTAG.Models; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; namespace IUT_ISTAG.Data { public class AppDbContext : IdentityDbContext, int> { public AppDbContext(DbContextOptions options) : base(options) { } protected override void OnModelCreating(ModelBuilder builder) { base.OnModelCreating(builder); // ========================= // Rename Identity Tables // ========================= builder.Entity() .ToTable("ApplicationUsers"); builder.Entity>() .ToTable("ApplicationRoles"); builder.Entity>() .ToTable("ApplicationUserRoles"); builder.Entity>() .ToTable("ApplicationUserClaims"); builder.Entity>() .ToTable("ApplicationUserLogins"); builder.Entity>() .ToTable("ApplicationRoleClaims"); builder.Entity>() .ToTable("ApplicationUserTokens"); builder.Entity>().HasData( new IdentityRole { Id = 1, Name = "Super_Admin", NormalizedName = "SUPER_ADMIN" }, new IdentityRole { Id = 2, Name = "Administrateur_Niveau_3", NormalizedName = "ADMINISTRATEUR_NIVEAU_3" }, new IdentityRole { Id = 3, Name = "Administrateur_Niveau_2", NormalizedName = "ADMINISTRATEUR_NIVEAU_2" }, new IdentityRole { Id = 4, Name = "Administrateur_Niveau_1", NormalizedName = "ADMINISTRATEUR_NIVEAU_1" }, new IdentityRole { Id = 5, Name = "Enseignant", NormalizedName = "Enseignant" }, new IdentityRole { Id = 6, Name = "Etudiant", NormalizedName = "ETUDIANT" } ); // ========================= // ADMIN USER // ========================= var admin = new ApplicationUser { Id = 1, UserName = "admin", NormalizedUserName = "ADMIN", PhoneNumber = "672651571", nom="admin", Email = "admin@istag.com", NormalizedEmail = "ADMIN@istag.com", EmailConfirmed = true, SecurityStamp = Guid.NewGuid().ToString() }; // HASH PASSWORD var passwordHasher = new PasswordHasher(); admin.PasswordHash = passwordHasher.HashPassword(admin, "Admin123!"); builder.Entity().HasData(admin); // ========================= // USER ROLE // ========================= builder.Entity>().HasData( new IdentityUserRole { UserId = 1, RoleId = 1 } ); } // tes tables métier /* public DbSet Action { get; set; } public DbSet Campus { get; set; } public DbSet CycleEtudes { get; set; } public DbSet Domaines { get; set; } public DbSet Filieres { get; set; } public DbSet Habilitations { get; set; } public DbSet niveau { get; set; } public DbSet Specialites { get; set; } public DbSet Type_users { get; set; } public DbSet User { get; set; } */ } }