Пример #1
0
        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();
                    }
                }
            }
        }
Пример #2
0
 public CatalogJsonRepository(JsonFileCatalogService catalogs)
 {
     Catalogs = catalogs.GetCatalogs();
 }
Пример #3
0
 public DataDoska(JsonFileCatalogService service)
 {
     repository = new CatalogJsonRepository(service).Catalogs;
 }