GGMM/GrossesMitaines/GrossesMitainesAPI/Data/InventoryContext.cs
MarcEricMartel dbc1c78f07 Woohoo
2022-10-16 08:25:21 -07:00

54 lines
2.0 KiB
C#

using Microsoft.EntityFrameworkCore;
using GrossesMitainesAPI.Models;
namespace GrossesMitainesAPI.Data;
public class InventoryContext : DbContext {
public DbSet<Product> Products { 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 {
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,
Quantity = 1,
ImageName = $"ceintureflechee"
});
modelBuilder.Entity<Product>().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,
Quantity = 54,
ImageName = $"pantouflesCH"
});
modelBuilder.Entity<Product>().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,
Quantity = 1,
ImageName = $"jeanlucmongrain"
});
}
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);
}
}