using Microsoft.EntityFrameworkCore; using GrossesMitainesAPI.Models; using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.AspNetCore.Identity; namespace GrossesMitainesAPI.Data; public class InventoryContext : IdentityDbContext { public DbSet Products { get; set; } public DbSet Addresses { get; set; } public DbSet Invoices { get; set; } public InventoryContext(DbContextOptions options) : base(options) { } protected override void OnModelCreating(ModelBuilder modelBuilder) { // Pour partir la BD. modelBuilder.Entity().HasData(new ProductModel { Id = 1, Title = @"Ceinture flèchée", Category = @"Linge", Description = @"Pour faire votre propre bonhomme de 1837, comme dans le bon vieux temps.", Status = ProductModel.States.Promotion, Price = 85.86M, PromoPrice = 29.99M, Quantity = 1, ImageName = @"$ceintureflechee.jpg" }); modelBuilder.Entity().HasData(new ProductModel { Id = 2, Title = @"Pantoufles du Canadien en Phentex", Category = @"Linge", Description = @"Parce que ça sent la coupe!", Status = ProductModel.States.Available, Price = 15.64M, PromoPrice = 9.99M, Quantity = 54, ImageName = @"$pantouflesCH.jpg" }); modelBuilder.Entity().HasData(new ProductModel { Id = 3, Title = @"Jean-Luc Mongrain", Category = @"Homme", Description = @"On ne lui ferait pas mal, en tout cas!!", Status = ProductModel.States.Clearance, Price = 1453.12M, PromoPrice = 999.99M, Quantity = 1, ImageName = @"$jeanlucmongrain.jpg" }); modelBuilder.Entity().HasData(new ProductModel { Id = 4, Title = @"T-Shirt", Category = @"Linge", Description = @"Tellement simple et comfortable.", Status = ProductModel.States.Available, Price = 12.12M, PromoPrice = 9.99M, Quantity = 143, ImageName = @"$tshirt.jpg" }); modelBuilder.Entity().HasData(new ProductModel { Id = 5, Title = @"Mitaines", Category = @"Vêtement d'extérieur", Description = @"Deux pour un!", Status = ProductModel.States.Available, Price = 8.18M, PromoPrice = 6.99M, Quantity = 1423, ImageName = @"$mitaines.jpg" }); modelBuilder.Entity().HasData(new ProductModel { Id = 6, Title = @"Foulard", Category = @"Vêtement d'extérieur", Description = @"Deux pour un!", Status = ProductModel.States.Promotion, Price = 10.56M, PromoPrice = 8.99M, Quantity = 14, ImageName = @"$foulard.jpg" }); modelBuilder.Entity().HasData(new ProductModel { Id = 7, Title = @"Jock-Strap en phentex", Category = @"Sous-Vêtement", Description = @"Pour garder le p'tit bout au chaud.", Status = ProductModel.States.Promotion, Price = 15.45M, PromoPrice = 12.99M, Quantity = 144, ImageName = @"$kokin.jpg" }); modelBuilder.Entity().HasData(new ProductModel { Id = 8, Title = @"Jock-Strap féminin en phentex", Category = @"Sous-Vêtement", Description = @"Pour garder l'absence de p'tit bout au chaud.", Status = ProductModel.States.Promotion, Price = 15.45M, PromoPrice = 12.99M, Quantity = 224, ImageName = @"$kokinfemme.jpg" }); modelBuilder.Entity().HasData(new ProductModel { Id = 9, Title = @"Bibi", Category = @"Alien", Description = @"En chiffon.", Status = ProductModel.States.Clearance, Price = 1045.45M, PromoPrice = 1023.99M, Quantity = 1, ImageName = @"$bibi.jpg" }); modelBuilder.Entity().HasData(new ProductModel { Id = 10, Title = @"Tuque en laine", Category = @"Vêtement d'extérieur", Description = @"En chiffon.", Status = ProductModel.States.Available, Price = 15.45M, PromoPrice = 12.99M, Quantity = 1, ImageName = @"$tuque.jpg" }); modelBuilder.Entity().HasData(new ProductModel { Id = 11, Title = @"Habit de Bonhomme Carnaval", Category = @"Vêtement d'extérieur", Description = @"Pour se faire taper dessus avec une poêle à frire tout en restant au chaud.", Status = ProductModel.States.Promotion, Price = 145.45M, PromoPrice = 123.99M, Quantity = 1, ImageName = @"$bonhomme.jpg" }); modelBuilder.Entity().HasData(new ProductModel { Id = 12, Title = @"Gauze en phentex", Category = @"Autre", Description = @"Pour se pêter la fiole avec style.", Status = ProductModel.States.BackOrder, Price = 145.45M, PromoPrice = 123.99M, Quantity = 0, ImageName = @"$gauze.jpg" }); modelBuilder.Entity().HasData(new ProductModel { Id = 13, Title = @"Petit Jésus de plâtre", Category = @"Homme", Description = @"En chiffon.", Status = ProductModel.States.Clearance, Price = 145.45M, PromoPrice = 123.99M, Quantity = 1, ImageName = @"$jesus.jpg" }); modelBuilder.Entity().HasData(new ProductModel { Id = 14, Title = @"VHS de la Guerre des Tuques", Category = @"Autre", Description = @"À écouter dans l'habit de Bonhomme Carnaval tant que possible.", Status = ProductModel.States.Clearance, Price = 3.45M, PromoPrice = 1.99M, Quantity = 164363, ImageName = @"$vhs.jpg" }); modelBuilder.Entity().HasData(new ProductModel { Id = 15, Title = @"Gilet pare-balle en laine", Category = @"Linge", Description = @"(N'est pas réellement pare-balle).", Status = ProductModel.States.Clearance, Price = 1435.45M, PromoPrice = 1223.99M, Quantity = 18, ImageName = @"$chandailquetaine.jpg" }); modelBuilder.Entity().HasData(new ProductModel { Id = 16, Title = @"Doudou", Category = @"Autre", Description = @"Pour s'éffoirer le nez dedans.", Status = ProductModel.States.Available, Price = 14.45M, PromoPrice = 13.99M, Quantity = 14, ImageName = @"$doudou.jpg" }); modelBuilder.Entity().HasData(new ProductModel { Id = 17, Title = @"Mitaines pas de doigts", Category = @"Vêtements d'extérieur", Description = @"Pour avoir l'air thug en hiver.", Status = ProductModel.States.Available, Price = 9.45M, PromoPrice = 8.99M, Quantity = 16, ImageName = @"$mitaines2.jpg" }); // Source: Notre TP Web 4DW. string AdministrateurID = "c9e08b20-d8a5-473f-9f52-572eb23c12af"; string ClientID = "1b7b9c55-c746-493a-a24f-3d5ca937298e"; string AdminID = "ecf7503a-591c-454e-a824-048e10bd0474"; InventoryUser admin = new InventoryUser() { FirstName = "Roger", LastName = "Admin", NormalizedUserName = "ADMIN", UserName = "Admin", Id = AdminID, NormalizedEmail = "ADMIN@ADMIN.COM", Email = "admin@admin.com" }; //admin.Adresses.Add(new AddressModel() { // CivicNumber = 1234, // Appartment = "B", // Street = "Rue Pierre-Falardeau", // City = "Saint-Chrysostome", // PostalCode = "H0H0H0", // Province = "QC", // Country = "Canada" //}); admin.PasswordHash = new PasswordHasher().HashPassword(admin, "Qwerty123!"); modelBuilder.Entity().HasData(admin); modelBuilder.Entity().HasData( new IdentityRole { Id = AdministrateurID, Name = "Administrateur", NormalizedName = "ADMINISTRATEUR" }, new IdentityRole { Id = ClientID, Name = "Client", NormalizedName = "CLIENT" } ); modelBuilder.Entity>().HasData( new IdentityUserRole { RoleId = AdministrateurID, UserId = AdminID }, new IdentityUserRole { RoleId = ClientID, UserId = AdminID } ); base.OnModelCreating(modelBuilder); } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { var configuration = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json") .Build(); var connectionString = configuration.GetConnectionString("DefaultConnection"); optionsBuilder.UseSqlServer(connectionString); } }