2022-06-08 08:53:44 +02:00
|
|
|
|
using Aps_Single_Page_Anwendung.Models;
|
|
|
|
|
using Aps_Single_Page_Anwendung.Repositories;
|
|
|
|
|
using Microsoft.AspNetCore.Hosting;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
namespace Single_Page_Anwendung.Models
|
2022-06-07 14:35:06 +02:00
|
|
|
|
{
|
|
|
|
|
public class DatenEinlesen
|
|
|
|
|
{
|
2022-06-08 08:53:44 +02:00
|
|
|
|
public static void Initialize(IServiceProvider serviceProvider)
|
|
|
|
|
{
|
|
|
|
|
// Holy shit Oo
|
|
|
|
|
using (var futterContext = new FutterContext(serviceProvider.GetRequiredService<DbContextOptions<FutterContext>>()))
|
|
|
|
|
{
|
|
|
|
|
if (futterContext.Speisen.Any())
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var kategorieRepository =
|
|
|
|
|
new FileKategorieRepository(serviceProvider.GetRequiredService<IWebHostEnvironment>());
|
|
|
|
|
|
|
|
|
|
var kategorien = kategorieRepository.GetKategorien().ToList();
|
|
|
|
|
|
|
|
|
|
kategorien.ForEach(k =>
|
|
|
|
|
{
|
|
|
|
|
k.Id = 0;
|
|
|
|
|
foreach (var speise in k.Speisen)
|
|
|
|
|
{
|
|
|
|
|
speise.Id = 0;
|
|
|
|
|
speise.KategorieId = 0;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
futterContext.Kategorien.AddRange(kategorien);
|
|
|
|
|
futterContext.SaveChanges();
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-06-07 14:35:06 +02:00
|
|
|
|
}
|
|
|
|
|
}
|