Пример #1
0
        // method that create

        public static void SeedData(IServiceProvider serviceProvider, UserManager <ApplicationUser> users, IConfiguration _config)
        {
            using (var dbContext = new AsyncInnDbContext(serviceProvider.GetRequiredService <DbContextOptions <AsyncInnDbContext> >()))
            {
                dbContext.Database.EnsureCreated();
                AddRoles(dbContext);
                SeedUsers(users, _config);
            }
        }
Пример #2
0
        private static void AddRoles(AsyncInnDbContext context)
        {
            if (context.Roles.Any())
            {
                return;
            }

            foreach (var role in Roles)
            {
                context.Roles.Add(role);
                context.SaveChanges();
            }
        }