Exemple #1
0
        public static async Task InitializeNerdDinner(IServiceProvider provider)
        {
            NerdDinnerDbContext           dbContext   = provider.GetService <NerdDinnerDbContext>();
            UserManager <ApplicationUser> userManager = provider.GetService <UserManager <ApplicationUser> >();

            INerdDinnerRepository repository = new NerdDinnerRepository(dbContext);

            var users   = GetUsers();
            var dinners = GetDinners();

            foreach (RegisterViewModel user in users)
            {
                var applicationUser = new ApplicationUser
                {
                    UserName = user.Email
                };

                await userManager.CreateAsync(applicationUser, user.Password);
            }

            foreach (Dinner dinner in dinners)
            {
                await repository.CreateDinnerAsync(dinner);
            }
        }
Exemple #2
0
        public static async Task InitializeNerdDinner(IServiceProvider provider)
        {
            using (var serviceScope = provider.GetRequiredService <IServiceScopeFactory>().CreateScope())
            {
                var db = serviceScope.ServiceProvider.GetService <NerdDinnerDbContext>();
                UserManager <ApplicationUser> userManager = provider.GetService <UserManager <ApplicationUser> >();

                INerdDinnerRepository repository = new NerdDinnerRepository(db);

                var users = GetUsers();

                foreach (RegisterViewModel user in users)
                {
                    var applicationUser = new ApplicationUser
                    {
                        UserName = user.Email
                    };

                    await userManager.CreateAsync(applicationUser, user.Password);
                }


                if (repository.Dinners.Count() == 0)
                {
                    var newDinners = GetDinners();
                    foreach (Dinner dinner in newDinners)
                    {
                        await repository.CreateDinnerAsync(dinner);
                    }
                }
            }
        }
Exemple #3
0
        public static async Task InitializeNerdDinner(IServiceProvider provider)
        {
            using (var serviceScope = provider.GetRequiredService <IServiceScopeFactory>().CreateScope())
            {
                var db = serviceScope.ServiceProvider.GetService <ApplicationDbContext>();

                INerdDinnerRepository repository = new NerdDinnerRepository(db);

                if (repository.Dinners.Count() == 0)
                {
                    var newDinners = GetDinners();
                    foreach (Dinner dinner in newDinners)
                    {
                        await repository.CreateDinnerAsync(dinner);
                    }
                }
            }
        }