Renvoit du rôle au frontend avec Get Login (UPDATE-DATABASE)
This commit is contained in:
@@ -6,205 +6,243 @@ using Microsoft.AspNetCore.Identity;
|
||||
namespace GrossesMitainesAPI.Data;
|
||||
|
||||
public class InventoryContext : IdentityDbContext<InventoryUser> {
|
||||
public DbSet<Product> Products { get; set; }
|
||||
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) {
|
||||
base.OnModelCreating(modelBuilder);
|
||||
|
||||
|
||||
// Pour partir la BD.
|
||||
modelBuilder.Entity<Product>().HasData(new Product {
|
||||
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 = Product.States.Promotion,
|
||||
Status = ProductModel.States.Promotion,
|
||||
Price = 85.86M,
|
||||
PromoPrice = 29.99M,
|
||||
Quantity = 1,
|
||||
ImageName = $"ceintureflechee"
|
||||
});
|
||||
modelBuilder.Entity<Product>().HasData(new Product {
|
||||
modelBuilder.Entity<ProductModel>().HasData(new ProductModel {
|
||||
Id = 2,
|
||||
Title = $"Pantoufles du Canadien en Phentex",
|
||||
Category = $"Linge",
|
||||
Description = $"Parce que ça sent la coupe!",
|
||||
Status = Product.States.Available,
|
||||
Status = ProductModel.States.Available,
|
||||
Price = 15.64M,
|
||||
PromoPrice = 9.99M,
|
||||
Quantity = 54,
|
||||
ImageName = $"pantouflesCH"
|
||||
});
|
||||
modelBuilder.Entity<Product>().HasData(new Product {
|
||||
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 = Product.States.Clearance,
|
||||
Status = ProductModel.States.Clearance,
|
||||
Price = 1453.12M,
|
||||
PromoPrice = 999.99M,
|
||||
Quantity = 1,
|
||||
ImageName = $"jeanlucmongrain"
|
||||
});
|
||||
modelBuilder.Entity<Product>().HasData(new Product {
|
||||
modelBuilder.Entity<ProductModel>().HasData(new ProductModel {
|
||||
Id = 4,
|
||||
Title = $"T-Shirt",
|
||||
Category = $"Linge",
|
||||
Description = $"Tellement simple et comfortable.",
|
||||
Status = Product.States.Available,
|
||||
Status = ProductModel.States.Available,
|
||||
Price = 12.12M,
|
||||
PromoPrice = 9.99M,
|
||||
Quantity = 143,
|
||||
ImageName = $"tshirt"
|
||||
});
|
||||
modelBuilder.Entity<Product>().HasData(new Product {
|
||||
modelBuilder.Entity<ProductModel>().HasData(new ProductModel {
|
||||
Id = 5,
|
||||
Title = $"Mitaines",
|
||||
Category = $"Vêtement d'extérieur",
|
||||
Description = $"Deux pour un!",
|
||||
Status = Product.States.Available,
|
||||
Status = ProductModel.States.Available,
|
||||
Price = 8.18M,
|
||||
PromoPrice = 6.99M,
|
||||
Quantity = 1423,
|
||||
ImageName = $"mitaines"
|
||||
});
|
||||
modelBuilder.Entity<Product>().HasData(new Product {
|
||||
modelBuilder.Entity<ProductModel>().HasData(new ProductModel {
|
||||
Id = 6,
|
||||
Title = $"Foulard",
|
||||
Category = $"Vêtement d'extérieur",
|
||||
Description = $"Deux pour un!",
|
||||
Status = Product.States.Promotion,
|
||||
Status = ProductModel.States.Promotion,
|
||||
Price = 10.56M,
|
||||
PromoPrice = 8.99M,
|
||||
Quantity = 14,
|
||||
ImageName = $"foulard"
|
||||
});
|
||||
modelBuilder.Entity<Product>().HasData(new Product {
|
||||
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 = Product.States.Promotion,
|
||||
Status = ProductModel.States.Promotion,
|
||||
Price = 15.45M,
|
||||
PromoPrice = 12.99M,
|
||||
Quantity = 144,
|
||||
ImageName = $"kokin"
|
||||
});
|
||||
modelBuilder.Entity<Product>().HasData(new Product {
|
||||
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 = Product.States.Promotion,
|
||||
Status = ProductModel.States.Promotion,
|
||||
Price = 15.45M,
|
||||
PromoPrice = 12.99M,
|
||||
Quantity = 224,
|
||||
ImageName = $"kokin"
|
||||
});
|
||||
modelBuilder.Entity<Product>().HasData(new Product {
|
||||
modelBuilder.Entity<ProductModel>().HasData(new ProductModel {
|
||||
Id = 9,
|
||||
Title = $"Bibi",
|
||||
Category = $"Alien",
|
||||
Description = $"En chiffon.",
|
||||
Status = Product.States.Clearance,
|
||||
Status = ProductModel.States.Clearance,
|
||||
Price = 1045.45M,
|
||||
PromoPrice = 1023.99M,
|
||||
Quantity = 1,
|
||||
ImageName = $"bibi"
|
||||
});
|
||||
modelBuilder.Entity<Product>().HasData(new Product {
|
||||
modelBuilder.Entity<ProductModel>().HasData(new ProductModel {
|
||||
Id = 10,
|
||||
Title = $"Tuque en laine",
|
||||
Category = $"Vêtement d'extérieur",
|
||||
Description = $"En chiffon.",
|
||||
Status = Product.States.Available,
|
||||
Status = ProductModel.States.Available,
|
||||
Price = 15.45M,
|
||||
PromoPrice = 12.99M,
|
||||
Quantity = 1,
|
||||
ImageName = $"tuque"
|
||||
});
|
||||
modelBuilder.Entity<Product>().HasData(new Product {
|
||||
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 = Product.States.Promotion,
|
||||
Status = ProductModel.States.Promotion,
|
||||
Price = 145.45M,
|
||||
PromoPrice = 123.99M,
|
||||
Quantity = 1,
|
||||
ImageName = $"bonhomme"
|
||||
});
|
||||
modelBuilder.Entity<Product>().HasData(new Product {
|
||||
modelBuilder.Entity<ProductModel>().HasData(new ProductModel {
|
||||
Id = 12,
|
||||
Title = $"Gauze en phentex",
|
||||
Category = $"Autre",
|
||||
Description = $"Pour se pêter la fiole avec style.",
|
||||
Status = Product.States.BackOrder,
|
||||
Status = ProductModel.States.BackOrder,
|
||||
Price = 145.45M,
|
||||
PromoPrice = 123.99M,
|
||||
Quantity = 0,
|
||||
ImageName = $"gauze"
|
||||
});
|
||||
modelBuilder.Entity<Product>().HasData(new Product {
|
||||
modelBuilder.Entity<ProductModel>().HasData(new ProductModel {
|
||||
Id = 13,
|
||||
Title = $"Petit Jésus de plâtre",
|
||||
Category = $"Homme",
|
||||
Description = $"En chiffon.",
|
||||
Status = Product.States.Clearance,
|
||||
Status = ProductModel.States.Clearance,
|
||||
Price = 145.45M,
|
||||
PromoPrice = 123.99M,
|
||||
Quantity = 1,
|
||||
ImageName = $"jesus"
|
||||
});
|
||||
modelBuilder.Entity<Product>().HasData(new Product {
|
||||
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 = Product.States.Clearance,
|
||||
Status = ProductModel.States.Clearance,
|
||||
Price = 3.45M,
|
||||
PromoPrice = 1.99M,
|
||||
Quantity = 164363,
|
||||
ImageName = $"vhs"
|
||||
});
|
||||
modelBuilder.Entity<Product>().HasData(new Product {
|
||||
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 = Product.States.Clearance,
|
||||
Status = ProductModel.States.Clearance,
|
||||
Price = 1435.45M,
|
||||
PromoPrice = 1223.99M,
|
||||
Quantity = 18,
|
||||
ImageName = $"chandailquetaine"
|
||||
});
|
||||
modelBuilder.Entity<Product>().HasData(new Product {
|
||||
modelBuilder.Entity<ProductModel>().HasData(new ProductModel {
|
||||
Id = 16,
|
||||
Title = $"Doudou",
|
||||
Category = $"Autre",
|
||||
Description = $"Pour s'éffoirer le nez dedans.",
|
||||
Status = Product.States.Available,
|
||||
Status = ProductModel.States.Available,
|
||||
Price = 14.45M,
|
||||
PromoPrice = 13.99M,
|
||||
Quantity = 14,
|
||||
ImageName = $"doudou"
|
||||
});
|
||||
modelBuilder.Entity<Product>().HasData(new Product {
|
||||
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 = Product.States.Available,
|
||||
Status = ProductModel.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" };
|
||||
// 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()
|
||||
|
@@ -1,28 +1,13 @@
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using GrossesMitainesAPI.Models;
|
||||
|
||||
namespace GrossesMitainesAPI.Data;
|
||||
public class InventoryUser : IdentityUser {
|
||||
public class Address {
|
||||
[Key]
|
||||
public int Id { get; set; }
|
||||
[Required, Range(1, int.MaxValue)]
|
||||
public int CivicNumber { get; set; }
|
||||
public string? Appartment { get; set; }
|
||||
[Required, MinLength(3), MaxLength(50)]
|
||||
public string Street { get; set; }
|
||||
[Required, MinLength(4), MaxLength(50)]
|
||||
public string City { get; set; }
|
||||
[Required, MaxLength(2)]
|
||||
public string Province { get; set; }
|
||||
[Required, MinLength(4), MaxLength(30)]
|
||||
public string Country { get; set; }
|
||||
// Source pour regex: https://stackoverflow.com/questions/15774555/efficient-regex-for-canadian-postal-code-function
|
||||
[Required, RegularExpression(@"/^[ABCEGHJ-NPRSTVXY]\d[ABCEGHJ-NPRSTV-Z][ -]?\d[ABCEGHJ-NPRSTV-Z]\d$/i")]
|
||||
public string PostalCode { get; set; }
|
||||
}
|
||||
|
||||
public List<Address> Adresses { get; set; }
|
||||
|
||||
public class InventoryUser : IdentityUser {
|
||||
[Required, MinLength(2), MaxLength(30)]
|
||||
public string FirstName { get; set; }
|
||||
[Required, MinLength(1), MaxLength(30)]
|
||||
public string LastName { get; set; }
|
||||
public List<AddressModel> Adresses { get; set; }
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user