public static async Task SeedAsync(UserManager <ApplicationUser> userManager, RoleManager <IdentityRole> roleManager, BarracudaDbContext context) { try { // We're using command-type migration with dotnet ef tool. // If not needed migration history then reopen this. if (!await context.Database.EnsureCreatedAsync()) { await context.Database.MigrateAsync(); } // await SeedRoles(roleManager); // await SeedUsers(userManager, context); // // if ((await context.Database.GetPendingMigrationsAsync()).Any()) // { // await context.Database.MigrateAsync(); // } } catch (Exception ex) { throw new ApplicationException(ex.Message); } }
private static async Task SeedUsers(UserManager <ApplicationUser> userManager, BarracudaDbContext context) { if (userManager.Users.Any()) { return; } var playerList = new List <ApplicationUser> { new ApplicationUser() { UserName = "******", Email = "*****@*****.**", FirstName = "Quentin", LastName = "Tarantino", CreateDate = DateTime.UtcNow }, new ApplicationUser() { UserName = "******", Email = "*****@*****.**", FirstName = "Martin", LastName = "Scorsese", CreateDate = DateTime.UtcNow }, new ApplicationUser() { UserName = "******", Email = "*****@*****.**", FirstName = "David", LastName = "Fincher", CreateDate = DateTime.UtcNow } }; playerList.ForEach(player => { player.PasswordHash = CreatePasswordHash(player, "admin"); var identityResult = userManager.CreateAsync(player).Result; if (identityResult.Succeeded) { userManager.AddToRoleAsync(player, "Admin"); } }); await context.SaveChangesAsync(); }
public BarracudaEfRepository(BarracudaDbContext dbContext) : base(dbContext) { }