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 InventoryContext(DbContextOptions options) : base(options) { } protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); // Pour partir la BD. modelBuilder.Entity().HasData(new Product { Id = 1, Title = $"Ceinture flèchée", Category = $"Linge", Description = $"Pour faire votre propre bonhomme de 1837, comme dans le bon vieux temps.", Status = Product.States.Promotion, Price = 85.86M, PromoPrice = 29.99M, Quantity = 1, ImageName = $"ceintureflechee" }); modelBuilder.Entity().HasData(new Product { Id = 2, Title = $"Pantoufles du Canadien en Phentex", Category = $"Linge", Description = $"Parce que ça sent la coupe!", Status = Product.States.Available, Price = 15.64M, PromoPrice = 9.99M, Quantity = 54, ImageName = $"pantouflesCH" }); modelBuilder.Entity().HasData(new Product { Id = 3, Title = $"Jean-Luc Mongrain", Category = $"Homme", Description = $"On ne lui ferait pas mal, en tout cas!!", Status = Product.States.Clearance, Price = 1453.12M, PromoPrice = 999.99M, Quantity = 1, ImageName = $"jeanlucmongrain" }); modelBuilder.Entity().HasData(new Product { Id = 4, Title = $"T-Shirt", Category = $"Linge", Description = $"Tellement simple et comfortable.", Status = Product.States.Available, Price = 12.12M, PromoPrice = 9.99M, Quantity = 143, ImageName = $"tshirt" }); modelBuilder.Entity().HasData(new Product { Id = 5, Title = $"Mitaines", Category = $"Vêtement d'extérieur", Description = $"Deux pour un!", Status = Product.States.Available, Price = 8.18M, PromoPrice = 6.99M, Quantity = 1423, ImageName = $"mitaines" }); modelBuilder.Entity().HasData(new Product { Id = 6, Title = $"Foulard", Category = $"Vêtement d'extérieur", Description = $"Deux pour un!", Status = Product.States.Promotion, Price = 10.56M, PromoPrice = 8.99M, Quantity = 14, ImageName = $"foulard" }); modelBuilder.Entity().HasData(new Product { Id = 7, Title = $"Jock-Strap en phentex", Category = $"Sous-Vêtement", Description = $"Pour garder le p'tit bout au chaud.", Status = Product.States.Promotion, Price = 15.45M, PromoPrice = 12.99M, Quantity = 144, ImageName = $"kokin" }); modelBuilder.Entity().HasData(new Product { 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 = Product.States.Promotion, Price = 15.45M, PromoPrice = 12.99M, Quantity = 224, ImageName = $"kokin" }); modelBuilder.Entity().HasData(new Product { Id = 9, Title = $"Bibi", Category = $"Alien", Description = $"En chiffon.", Status = Product.States.Clearance, Price = 1045.45M, PromoPrice = 1023.99M, Quantity = 1, ImageName = $"bibi" }); modelBuilder.Entity().HasData(new Product { Id = 10, Title = $"Tuque en laine", Category = $"Vêtement d'extérieur", Description = $"En chiffon.", Status = Product.States.Available, Price = 15.45M, PromoPrice = 12.99M, Quantity = 1, ImageName = $"tuque" }); modelBuilder.Entity().HasData(new Product { 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 = Product.States.Promotion, Price = 145.45M, PromoPrice = 123.99M, Quantity = 1, ImageName = $"bonhomme" }); modelBuilder.Entity().HasData(new Product { Id = 12, Title = $"Gauze en phentex", Category = $"Autre", Description = $"Pour se pêter la fiole avec style.", Status = Product.States.BackOrder, Price = 145.45M, PromoPrice = 123.99M, Quantity = 0, ImageName = $"gauze" }); modelBuilder.Entity().HasData(new Product { Id = 13, Title = $"Petit Jésus de plâtre", Category = $"Homme", Description = $"En chiffon.", Status = Product.States.Clearance, Price = 145.45M, PromoPrice = 123.99M, Quantity = 1, ImageName = $"jesus" }); modelBuilder.Entity().HasData(new Product { Id = 14, Title = $"VHS de la Guerre des Tuques", Category = $"Autre", Description = $"À écouter dans l'habit de Bonhomme Carnaval tant que possible.", Status = Product.States.Clearance, Price = 3.45M, PromoPrice = 1.99M, Quantity = 164363, ImageName = $"vhs" }); modelBuilder.Entity().HasData(new Product { Id = 15, Title = $"Gilet pare-balle en laine", Category = $"Linge", Description = $"(N'est pas réellement pare-balle).", Status = Product.States.Clearance, Price = 1435.45M, PromoPrice = 1223.99M, Quantity = 18, ImageName = $"chandailquetaine" }); modelBuilder.Entity().HasData(new Product { Id = 16, Title = $"Doudou", Category = $"Autre", Description = $"Pour s'éffoirer le nez dedans.", Status = Product.States.Available, Price = 14.45M, PromoPrice = 13.99M, Quantity = 14, ImageName = $"doudou" }); modelBuilder.Entity().HasData(new Product { Id = 17, Title = $"Mitaines pas de doigts", Category = $"Vêtements d'extérieur", Description = $"Pour avoir l'air thug en hiver.", Status = Product.States.Available, Price = 9.45M, PromoPrice = 8.99M, Quantity = 16, ImageName = $"mitaines2" }); InventoryUser admin = new InventoryUser() { NormalizedUserName = "admin", UserName = "Admin", NormalizedEmail = "admin@admin.com", Email = "admin@admin.com" }; admin.PasswordHash = new PasswordHasher().HashPassword(admin, "Qwerty123!"); modelBuilder.Entity().HasData(admin); } 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); } }