Upload project.
This commit is contained in:
58
ThAmCo.Catering/Data/CateringDbContext.cs
Normal file
58
ThAmCo.Catering/Data/CateringDbContext.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
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" }
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
20
ThAmCo.Catering/Data/FoodBooking.cs
Normal file
20
ThAmCo.Catering/Data/FoodBooking.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace ThAmCo.Catering.Data
|
||||
{
|
||||
public class FoodBooking
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public int MenuId { get; set; }
|
||||
|
||||
public Menu Menu { get; set; }
|
||||
|
||||
public string Notes { get; set; }
|
||||
}
|
||||
}
|
||||
18
ThAmCo.Catering/Data/Menu.cs
Normal file
18
ThAmCo.Catering/Data/Menu.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ThAmCo.Catering.Data
|
||||
{
|
||||
public class Menu
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public string Items { get; set; }
|
||||
|
||||
public double Price { get; set; }
|
||||
|
||||
public List<FoodBooking> FoodBookings { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user