GGMM/GrossesMitaines/GrossesMitainesAPI/Data/InventoryContext.cs

45 lines
1.7 KiB
C#
Raw Normal View History

2022-10-08 13:22:12 -04:00
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,
2022-10-08 14:02:05 -04:00
Title = $"Ceinture flèchée",
Description = $"Pour faire votre propre bonhomme de 1837, comme dans le bon vieux temps.",
Price = 85.86M,
2022-10-09 13:18:39 -04:00
ImageName = $"ceintureflechee"
2022-10-08 14:02:05 -04:00
});
modelBuilder.Entity<Product>().HasData(new Product {
Id = 2,
Title = $"Pantoufles du Canadien en Phentex",
Description = $"Parce que ça sent la coupe!",
Price = 15.64M,
2022-10-09 13:18:39 -04:00
ImageName = $"pantouflesCH"
2022-10-08 14:02:05 -04:00
});
modelBuilder.Entity<Product>().HasData(new Product {
Id = 3,
Title = $"Jean-Luc Mongrain",
Description = $"On ne lui ferait pas mal, en tout cas!!",
Price = 1453.12M,
2022-10-09 13:18:39 -04:00
ImageName = $"jeanlucmongrain"
2022-10-08 13:22:12 -04:00
});
}
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);
}
}