Ejemplo n.º 1
0
        public static async Task LoadVehicles(DataContext context)
        {
            if (await context.Vehicles.AnyAsync())
            {
                return;
            }

            var vehiclesData = await File.ReadAllTextAsync("Data/vehicles.json");

            var vehicles = JsonSerializer.Deserialize <List <Vehicle> >(vehiclesData);

            await context.AddRangeAsync(vehicles);

            await context.SaveChangesAsync();
        }
Ejemplo n.º 2
0
        public static async Task LoadBrands(DataContext context)
        {
            if (await context.Brands.AnyAsync())
            {
                return;
            }

            var brandsData = await File.ReadAllTextAsync("Data/brands.json");

            var brands = JsonSerializer.Deserialize <List <Brand> >(brandsData);

            await context.AddRangeAsync(brands);

            await context.SaveChangesAsync();
        }