public static void Initialize( PeopleDbContext context, //Database RoleManager <IdentityRole> roleManager, //Role UserManager <AppUser> AppUser) //User { //context.Database.EnsureCreated();//If not using EF migrations context.Database.Migrate(); if (context.Roles.Any()) //letar efter roller i databasen { return; // } //----------Seed into database -------------------------------------- string[] rolesToSeed = new string[] { "Admin", "User" }; foreach (var roleName in rolesToSeed) { IdentityRole role = new IdentityRole(roleName); var result = roleManager.CreateAsync(role).Result; if (!result.Succeeded) { throw new Exception("Faild to create Role" + roleName); } } AppUser user = new AppUser() { UserName = "******", FirstName = "Admin", LastName = "Admin", BirthDate = "2020", Email = "[email protected]", PhoneNumber = "123456789" }; IdentityResult resultUser = AppUser.CreateAsync(user, "Qwer1234!").Result; if (!resultUser.Succeeded) { throw new Exception("Faild to create Admin Acc: AdminPower"); } IdentityResult resultAssign = AppUser.AddToRoleAsync(user, rolesToSeed[0]).Result; if (!resultAssign.Succeeded) { throw new Exception($"Faild to grant Admin {rolesToSeed[0]} to AdminPower"); } }
public DbCountryRepo(PeopleDbContext peopleDbContext) { _peopleDbContext = peopleDbContext; }
public DbCityRepo(PeopleDbContext peopleDbContext) { _peopleDbContext = peopleDbContext; }
public DatabasePeopleRepo(PeopleDbContext peopleDbContext) { _peopleDbContext = peopleDbContext; }
public DbPersonLanguageRepo(PeopleDbContext peopleDbContext) { _peopleDbContext = peopleDbContext; }