59 lines
1.8 KiB
C#
59 lines
1.8 KiB
C#
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<Menu> Menus { get; set; }
|
|
public DbSet<FoodBooking> FoodBookings { get; set; }
|
|
|
|
private readonly IHostingEnvironment _hostEnv;
|
|
|
|
public CateringDbContext(DbContextOptions<CateringDbContext> 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<Menu>()
|
|
.HasKey(m => m.Id);
|
|
|
|
builder.Entity<FoodBooking>()
|
|
.HasKey(f => f.Id);
|
|
|
|
builder.Entity<Menu>()
|
|
.HasMany(f => f.FoodBookings)
|
|
.WithOne(m => m.Menu)
|
|
.HasForeignKey(m => m.Id);
|
|
|
|
|
|
|
|
if (_hostEnv != null && _hostEnv.IsDevelopment())
|
|
{
|
|
builder.Entity<Menu>()
|
|
.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" }
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|