using System; using System.Collections.Generic; using System.Linq; using Microsoft.AspNetCore.Hosting; using Microsoft.EntityFrameworkCore; using ThAmCo.Catering.Data; namespace ThAmCo.Venues.Data { public class CateringDbContext : DbContext { public DbSet Menus { get; set; } public DbSet FoodBookings { get; set; } private readonly IHostingEnvironment _hostEnv; public CateringDbContext(DbContextOptions options, IHostingEnvironment env) : base(options) { _hostEnv = env; } protected override void OnConfiguring(DbContextOptionsBuilder builder) { base.OnConfiguring(builder); } protected override void OnModelCreating(ModelBuilder builder) { base.OnModelCreating(builder); builder.HasDefaultSchema("thamco.catering"); builder.Entity() .HasKey(m => m.Id); builder.Entity() .HasKey(f => f.Id); builder.Entity() .HasMany(f => f.FoodBookings) .WithOne(m => m.Menu) .HasForeignKey(m => m.Id); if (_hostEnv != null && _hostEnv.IsDevelopment()) { builder.Entity() .HasData( new Menu { Id = 1, Price = 8.50, Items = "Chicken Pate, Chicken Roast, Chicken Cake" }, new Menu { Id = 2, Price = 7.50, Items = "Toast, Cheese On Toast, Jam on Toast" }, new Menu { Id = 3, Price = 9, Items = "Mac and Cheese, Alan's Special, Cheesecake" } ); } } } }