423 lines
		
	
	
		
			18 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			423 lines
		
	
	
		
			18 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
using Microsoft.EntityFrameworkCore;
 | 
						|
using GrossesMitainesAPI.Models;
 | 
						|
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
 | 
						|
using Microsoft.AspNetCore.Identity;
 | 
						|
 | 
						|
namespace GrossesMitainesAPI.Data;
 | 
						|
 | 
						|
public class InventoryContext : IdentityDbContext<InventoryUser> {
 | 
						|
    public DbSet<ProductModel> Products { get; set; }
 | 
						|
    public DbSet<AddressModel> Addresses { get; set; }
 | 
						|
    public DbSet<InvoiceModel> Invoices { get; set; }
 | 
						|
 | 
						|
    public InventoryContext(DbContextOptions<InventoryContext> options) : base(options) { }
 | 
						|
 | 
						|
    protected override void OnModelCreating(ModelBuilder modelBuilder) {
 | 
						|
 | 
						|
 | 
						|
        // Pour partir la BD.
 | 
						|
        modelBuilder.Entity<ProductModel>().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<ProductModel>().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<ProductModel>().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<ProductModel>().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<ProductModel>().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<ProductModel>().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<ProductModel>().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<ProductModel>().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<ProductModel>().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<ProductModel>().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<ProductModel>().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<ProductModel>().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<ProductModel>().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<ProductModel>().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<ProductModel>().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<ProductModel>().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<ProductModel>().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"
 | 
						|
        });
 | 
						|
        modelBuilder.Entity<ProductModel>().HasData(new ProductModel {
 | 
						|
            Id = 18,
 | 
						|
            Title = @"Longues mitaines pas de doigts",
 | 
						|
            Category = @"Vêtements d'extérieur",
 | 
						|
            Description = @"Pour avoir plus l'air thug en hiver.",
 | 
						|
            Status = ProductModel.States.Discontinued,
 | 
						|
            Price = 10.45M,
 | 
						|
            PromoPrice = 9.99M,
 | 
						|
            Quantity = 10,
 | 
						|
            ImageName = @"$longmitaines.jpg"
 | 
						|
        });
 | 
						|
        modelBuilder.Entity<ProductModel>().HasData(new ProductModel {
 | 
						|
            Id = 19,
 | 
						|
            Title = @"Pantalons slacks",
 | 
						|
            Category = @"Linge",
 | 
						|
            Description = @"Pour les journées bs",
 | 
						|
            Status = ProductModel.States.BackOrder,
 | 
						|
            Price = 69.99M,
 | 
						|
            PromoPrice = 49.99M,
 | 
						|
            Quantity = 0,
 | 
						|
            ImageName = @"$pantalon.jpg"
 | 
						|
        });
 | 
						|
        modelBuilder.Entity<ProductModel>().HasData(new ProductModel {
 | 
						|
            Id = 20,
 | 
						|
            Title = @"Programmer Socks",
 | 
						|
            Category = @"Linge",
 | 
						|
            Description = @"Pour commencer à apprendre rust et utiliser linux",
 | 
						|
            Status = ProductModel.States.Promotion,
 | 
						|
            Price = 23.50M,
 | 
						|
            PromoPrice = 19.99M,
 | 
						|
            Quantity = 3,
 | 
						|
            ImageName = @"$thighs.jpg"
 | 
						|
        });
 | 
						|
        modelBuilder.Entity<ProductModel>().HasData(new ProductModel {
 | 
						|
            Id = 21,
 | 
						|
            Title = @"Col-roulé",
 | 
						|
            Category = @"Linge",
 | 
						|
            Description = @"Show off que t'habites su'l plateau",
 | 
						|
            Status = ProductModel.States.Available,
 | 
						|
            Price = 149.99M,
 | 
						|
            PromoPrice = 99.99M,
 | 
						|
            Quantity = 14,
 | 
						|
            ImageName = @"$plateau.png"
 | 
						|
        });
 | 
						|
        modelBuilder.Entity<ProductModel>().HasData(new ProductModel {
 | 
						|
            Id = 22,
 | 
						|
            Title = @"Gros col-roulé",
 | 
						|
            Category = @"Linge",
 | 
						|
            Description = @"Ben oui je vais à l'UQAM comment t'as d'viné",
 | 
						|
            Status = ProductModel.States.Clearance,
 | 
						|
            Price = 149.99M,
 | 
						|
            PromoPrice = 99.99M,
 | 
						|
            Quantity = 4,
 | 
						|
            ImageName = @"$uqam.jpg"
 | 
						|
        });
 | 
						|
        modelBuilder.Entity<ProductModel>().HasData(new ProductModel {
 | 
						|
            Id = 23,
 | 
						|
            Title = @"SAQ",
 | 
						|
            Category = @"Établissement",
 | 
						|
            Description = @"Oui oui, une SAQ au complete",
 | 
						|
            Status = ProductModel.States.Available,
 | 
						|
            Price = 1000000.99M,
 | 
						|
            PromoPrice = 999999.99M,
 | 
						|
            Quantity = 1,
 | 
						|
            ImageName = @"$saq.jpg"
 | 
						|
        });
 | 
						|
        modelBuilder.Entity<ProductModel>().HasData(new ProductModel {
 | 
						|
            Id = 24,
 | 
						|
            Title = @"Lorem",
 | 
						|
            Category = @"Texte",
 | 
						|
            Description = @"Lorem ipsum dolor sit amet, 
 | 
						|
consectetur adipiscing elit. Vivamus sapien ipsum, 
 | 
						|
convallis quis justo ac, congue sollicitudin metus. 
 | 
						|
Vestibulum nec libero nulla. Integer a pretium dolor. 
 | 
						|
Phasellus vulputate iaculis ligula, sit amet suscipit 
 | 
						|
diam condimentum eu. Suspendisse blandit ipsum sed porttitor volutpat.
 | 
						|
Duis iaculis mauris a dapibus bibendum. Integer sollicitudin nunc et neque
 | 
						|
egestas sagittis. Etiam vitae ornare ex.",
 | 
						|
            Status = ProductModel.States.Promotion,
 | 
						|
            Price = 0.99M,
 | 
						|
            PromoPrice = 0.69M,
 | 
						|
            Quantity = 99,
 | 
						|
            ImageName = @"$lorem.jpg"
 | 
						|
        });
 | 
						|
        modelBuilder.Entity<ProductModel>().HasData(new ProductModel {
 | 
						|
            Id = 25,
 | 
						|
            Title = @"Bébé de laine",
 | 
						|
            Category = @"Homme",
 | 
						|
            Description = @"Quand un vrai coûte trop cher",
 | 
						|
            Status = ProductModel.States.Available,
 | 
						|
            Price = 10.99M,
 | 
						|
            PromoPrice = 5.99M,
 | 
						|
            Quantity = 15,
 | 
						|
            ImageName = @"$bebe.jpg"
 | 
						|
        });
 | 
						|
        modelBuilder.Entity<ProductModel>().HasData(new ProductModel {
 | 
						|
            Id = 26,
 | 
						|
            Title = @"Kit pour bébé",
 | 
						|
            Category = @"Linge",
 | 
						|
            Description = @"Un beau petit kit pas cher quand vous avez oublié le cadeau pour le shower qui s'en vient",
 | 
						|
            Status = ProductModel.States.Clearance,
 | 
						|
            Price = 39.99M,
 | 
						|
            PromoPrice = 29.99M,
 | 
						|
            Quantity = 10,
 | 
						|
            ImageName = @"$kitbebe.jpg"
 | 
						|
        });
 | 
						|
        modelBuilder.Entity<ProductModel>().HasData(new ProductModel {
 | 
						|
            Id = 27,
 | 
						|
            Title = @"TORTUE",
 | 
						|
            Category = @"Linge",
 | 
						|
            Description = @"Chris Pratt aime ben sauter dessus",
 | 
						|
            Status = ProductModel.States.Discontinued,
 | 
						|
            Price = 29.99M,
 | 
						|
            PromoPrice = 9.99M,
 | 
						|
            Quantity = 0,
 | 
						|
            ImageName = @"$koopa.jpg"
 | 
						|
        });
 | 
						|
        modelBuilder.Entity<ProductModel>().HasData(new ProductModel {
 | 
						|
            Id = 28,
 | 
						|
            Title = @"Patate de laine",
 | 
						|
            Category = @"Nourriture",
 | 
						|
            Description = @"*ne pa manger",
 | 
						|
            Status = ProductModel.States.Available,
 | 
						|
            Price = 1.99M,
 | 
						|
            PromoPrice = 0.99M,
 | 
						|
            Quantity = 58,
 | 
						|
            ImageName = @"$potato.jpg"
 | 
						|
        });
 | 
						|
        modelBuilder.Entity<ProductModel>().HasData(new ProductModel {
 | 
						|
            Id = 29,
 | 
						|
            Title = @"Monke :)",
 | 
						|
            Category = @"Animal",
 | 
						|
            Description = @"Les singes sont des mammifères de l'ordre des primates, généralement arboricoles, à la face souvent glabre et caractérisés par un encéphale développé et de longs membres terminés par des doigts. Bien que leur ressemblance avec l'Homme ait toujours frappé les esprits, la science a mis de nombreux siècles à prouver le lien étroit qui existe entre ceux-ci et l'espèce humaine.
 | 
						|
 | 
						|
Au sein des primates, les singes forment un infra-ordre monophylétique, si l'on y inclut le genre Homo, nommé Simiiformes et qui se divise entre les Platyrhiniens (singes du Nouveau Monde : Amérique centrale et méridionale) et les Catarhiniens (singes de l'Ancien Monde : Afrique et Asie tropicales). Ces derniers comprennent les hominoïdes, également appelés « grands singes », dont fait partie Homo sapiens et ses ancêtres les plus proches.
 | 
						|
 | 
						|
Même s'il ne fait plus de doute aujourd'hui que « l'Homme est un singe comme les autres », l'expression est majoritairement utilisée pour parler des animaux sauvages, et évoque un référentiel culturel, littéraire et artistique qui exclut l'espèce humaine.",
 | 
						|
            Status = ProductModel.States.Available,
 | 
						|
            Price = 299.99M,
 | 
						|
            PromoPrice = 99.99M,
 | 
						|
            Quantity = 58,
 | 
						|
            ImageName = @"$monke.png"
 | 
						|
        });
 | 
						|
        modelBuilder.Entity<ProductModel>().HasData(new ProductModel {
 | 
						|
            Id = 30,
 | 
						|
            Title = @"Phat Pikachu",
 | 
						|
            Category = @"Pokemon",
 | 
						|
            Description = @"It evolves from Pichu when leveled up with high friendship and evolves into Raichu when exposed to a Thunder Stone.
 | 
						|
 | 
						|
In Alola, Pikachu will evolve into Alolan Raichu when exposed to a Thunder Stone.
 | 
						|
 | 
						|
Pikachu has a Gigantamax form. Pikachu with the Gigantamax Factor cannot evolve.
 | 
						|
 | 
						|
In Pokémon Yellow, the starter Pikachu will refuse to evolve into Raichu unless it is traded and evolved on another save file. In Pokémon: Let's Go, Pikachu!, the player's starter Pikachu also will not evolve, but cannot be traded to become a Raichu.
 | 
						|
 | 
						|
Pikachu is popularly known as the mascot of the Pokémon franchise and one of Nintendo's major mascots.
 | 
						|
 | 
						|
It is also the game mascot and starter Pokémon of Pokémon Yellow and Let's Go, Pikachu!. It has made numerous appearances on the boxes of spin-off titles.
 | 
						|
 | 
						|
Pikachu is also the starter Pokémon of Pokémon Rumble Blast and Pokémon Rumble World.",
 | 
						|
            Status = ProductModel.States.Discontinued,
 | 
						|
            Price = 3.99M,
 | 
						|
            PromoPrice = 2.99M,
 | 
						|
            Quantity = 69,
 | 
						|
            ImageName = @"$pika.png"
 | 
						|
        });
 | 
						|
 | 
						|
 | 
						|
        // 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<InventoryUser>().HashPassword(admin, "Qwerty123!");
 | 
						|
        modelBuilder.Entity<InventoryUser>().HasData(admin);
 | 
						|
 | 
						|
        modelBuilder.Entity<IdentityRole>().HasData(
 | 
						|
            new IdentityRole { Id = AdministrateurID, Name = "Administrateur", NormalizedName = "ADMINISTRATEUR" },
 | 
						|
            new IdentityRole { Id = ClientID, Name = "Client", NormalizedName = "CLIENT" }
 | 
						|
            );
 | 
						|
 | 
						|
        modelBuilder.Entity<IdentityUserRole<string>>().HasData(
 | 
						|
            new IdentityUserRole<string> { RoleId = AdministrateurID, UserId = AdminID },
 | 
						|
            new IdentityUserRole<string> { 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);
 | 
						|
    }
 | 
						|
} |