public static void EnsurePopulated(IApplicationBuilder app) { JsonFileCatalogService contextJson = app.ApplicationServices.GetRequiredService <JsonFileCatalogService>(); DataDoska data = new DataDoska(contextJson); ApplicationDbContext context = app.ApplicationServices.GetRequiredService <ApplicationDbContext>(); context.Database.Migrate(); if (!context.Subtitles.Any()) { int count = 0; foreach (Catalog catalog in data.GetCatalogs()) { count++; context.Titles.Add(new Title { NameTitle = catalog.Title }); context.SaveChanges(); foreach (SubtitleJson sub in catalog.Subtitles) { context.Subtitles.Add(new Subtitle { NameSubtitle = sub.NameSubtitle, idTitle = count }); context.SaveChanges(); } } } }
public CatalogJsonRepository(JsonFileCatalogService catalogs) { Catalogs = catalogs.GetCatalogs(); }
public DataDoska(JsonFileCatalogService service) { repository = new CatalogJsonRepository(service).Catalogs; }