mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
parent
e6c447e26e
commit
7a81cc202f
1 changed files with 32 additions and 4 deletions
|
|
@ -29,18 +29,46 @@ public static bool AllMigrationsApplied(this DbContext context)
|
|||
|
||||
public static void EnsureSeeded(this FilterListsDbContext context)
|
||||
{
|
||||
if (context.FilterLists.Any()) return;
|
||||
Seed<License>(context);
|
||||
Seed<Syntax>(context);
|
||||
Seed<FilterList>(context);
|
||||
SeedLicenses(context);
|
||||
SeedSyntaxes(context);
|
||||
SeedFilterLists(context);
|
||||
}
|
||||
|
||||
//TODO: fix generic method to remove duplication of entity-specific methods
|
||||
private static void Seed<T>(DbContext context)
|
||||
{
|
||||
//if (context.?.Any()) return;
|
||||
var rows = JsonConvert.DeserializeObject<List<T>>(
|
||||
File.ReadAllText(SeedDirectory + Path.DirectorySeparatorChar + typeof(T).Name + ".json"));
|
||||
context.AddRange(rows);
|
||||
context.SaveChanges();
|
||||
}
|
||||
|
||||
private static void SeedLicenses(FilterListsDbContext context)
|
||||
{
|
||||
if (context.Licenses.Any()) return;
|
||||
var types = JsonConvert.DeserializeObject<List<License>>(
|
||||
File.ReadAllText(SeedDirectory + Path.DirectorySeparatorChar + typeof(License).Name + ".json"));
|
||||
context.AddRange(types);
|
||||
context.SaveChanges();
|
||||
}
|
||||
|
||||
private static void SeedSyntaxes(FilterListsDbContext context)
|
||||
{
|
||||
if (context.Syntaxes.Any()) return;
|
||||
var types = JsonConvert.DeserializeObject<List<Syntax>>(
|
||||
File.ReadAllText(SeedDirectory + Path.DirectorySeparatorChar + typeof(Syntax).Name + ".json"));
|
||||
context.AddRange(types);
|
||||
context.SaveChanges();
|
||||
}
|
||||
|
||||
private static void SeedFilterLists(FilterListsDbContext context)
|
||||
{
|
||||
if (context.FilterLists.Any()) return;
|
||||
var types = JsonConvert.DeserializeObject<List<FilterList>>(
|
||||
File.ReadAllText(SeedDirectory + Path.DirectorySeparatorChar + typeof(FilterList).Name + ".json"));
|
||||
context.AddRange(types);
|
||||
context.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue