public async Task AddRangeAsync()
        {
            var list = UserExtension.List();

            await _userRepository.AddRangeAsync(list);

            await _userRepository.SaveChangeAsync();
        }
Exemplo n.º 2
0
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseCookiePolicy();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });



            using (var scope = app.ApplicationServices.GetService <IServiceScopeFactory>().CreateScope())
            {
                using (var context = scope.ServiceProvider.GetRequiredService <ApplicationDbContext>())
                {
                    if (context.Database.EnsureCreated())
                    {
                        context.User.AddRange(UserExtension.List());
                        context.SaveChanges();
                    }
                }
            }
        }