Providing DbSeed
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Net.Http;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.EntityFrameworkCore.InMemory;
|
using Microsoft.EntityFrameworkCore.InMemory;
|
||||||
using WD7UVN_HFT_2023241.Models;
|
using WD7UVN_HFT_2023241.Models;
|
||||||
@@ -24,51 +25,59 @@ namespace WD7UVN_HFT_2023241.Repository
|
|||||||
{
|
{
|
||||||
optionsBuilder
|
optionsBuilder
|
||||||
.UseInMemoryDatabase("company");
|
.UseInMemoryDatabase("company");
|
||||||
|
|
||||||
//loading test values
|
|
||||||
Customers.Add(new Customer{
|
|
||||||
NAME = "Szemed Fénye Optika Kft.",
|
|
||||||
ID = 1,
|
|
||||||
SERVICE_ID = 1
|
|
||||||
});
|
|
||||||
|
|
||||||
Services.Add(new Service{
|
|
||||||
NAME = "Microsoft Exchange",
|
|
||||||
ID = 1,
|
|
||||||
MAINTAINER = 1,
|
|
||||||
});
|
|
||||||
|
|
||||||
Maintainers.Add(new MaintainerTeam{
|
|
||||||
ID = 1,
|
|
||||||
NAME = "Microsoft Team",
|
|
||||||
LEADER_EMPLOYEE_ID = 2
|
|
||||||
});
|
|
||||||
|
|
||||||
Employees.Add(new Employee{
|
|
||||||
ID = 1,
|
|
||||||
NAME = "Gipsz Jakab",
|
|
||||||
MANAGER = 2,
|
|
||||||
MAINTAINER_ID = 1
|
|
||||||
});
|
|
||||||
|
|
||||||
Employees.Add(new Employee{
|
|
||||||
NAME = "Székely Csaba",
|
|
||||||
ID = 3,
|
|
||||||
MANAGER = 2,
|
|
||||||
MAINTAINER_ID = 1
|
|
||||||
});
|
|
||||||
|
|
||||||
Employees.Add(new Employee{
|
|
||||||
NAME = "Nagy Krisztina",
|
|
||||||
ID = 2,
|
|
||||||
MAINTAINER_ID = 1
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
base.OnModelCreating(modelBuilder);
|
base.OnModelCreating(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity<Customer>(customer => customer
|
||||||
|
.HasOne<Service>()
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey(customer => customer.SERVICE_ID)
|
||||||
|
.OnDelete(DeleteBehavior.Cascade));
|
||||||
|
|
||||||
|
//loading test values
|
||||||
|
modelBuilder.Entity<Customer>().HasData(
|
||||||
|
new Customer{
|
||||||
|
NAME = "Szemed Fénye Optika Kft.",
|
||||||
|
ID = 1,
|
||||||
|
SERVICE_ID = 1}
|
||||||
|
);
|
||||||
|
|
||||||
|
modelBuilder.Entity<Service>().HasData(
|
||||||
|
new Service{
|
||||||
|
NAME = "Microsoft Exchange",
|
||||||
|
ID = 1,
|
||||||
|
MAINTAINER = 1}
|
||||||
|
);
|
||||||
|
|
||||||
|
modelBuilder.Entity<MaintainerTeam>().HasData(
|
||||||
|
new MaintainerTeam{
|
||||||
|
ID = 1,
|
||||||
|
NAME = "Microsoft Team",
|
||||||
|
LEADER_EMPLOYEE_ID = 2}
|
||||||
|
);
|
||||||
|
|
||||||
|
modelBuilder.Entity<Employee>().HasData(
|
||||||
|
new Employee{
|
||||||
|
ID = 1,
|
||||||
|
NAME = "Gipsz Jakab",
|
||||||
|
MANAGER = 2,
|
||||||
|
MAINTAINER_ID = 1},
|
||||||
|
|
||||||
|
new Employee{
|
||||||
|
NAME = "Székely Csaba",
|
||||||
|
ID = 3,
|
||||||
|
MANAGER = 2,
|
||||||
|
MAINTAINER_ID = 1},
|
||||||
|
|
||||||
|
new Employee{
|
||||||
|
NAME = "Nagy Krisztina",
|
||||||
|
ID = 2,
|
||||||
|
MAINTAINER_ID = 1}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user