public static async Task SeedAsync(IServiceProvider serviceProvider, string pw) { var adminId = await EnsureUser(serviceProvider, "admin_nick", "*****@*****.**", pw); await EnsureRole(serviceProvider, adminId, AppIdentityConstants.Roles.ADMINISTRATORS); var managerId = await EnsureUser(serviceProvider, "manager_nick", "*****@*****.**", pw); await EnsureRole(serviceProvider, managerId, AppIdentityConstants.Roles.MANAGERS); var devId = await EnsureUser(serviceProvider, "dev_nick", "*****@*****.**", pw); await EnsureRole(serviceProvider, managerId, AppIdentityConstants.Roles.DEVELOPERS); using (var context = new SkylineDbContext(serviceProvider.GetRequiredService <DbContextOptions <SkylineDbContext> >())) { SeedContactData(context, adminId); } }
public ContactRepository(SkylineDbContext dbContext) : base(dbContext) { }
public EFRepository(SkylineDbContext dbContext) { _dbContext = dbContext; }
public static void SeedContactData(SkylineDbContext context, string adminId) { if (context.Contacts.Any()) { return; // DB has been seeded } context.Contacts.AddRange( new Contact { Name = "叶文洁", Address = "文一路", City = "杭州市", Province = "浙江省", Zip = "310000", Email = "*****@*****.**", MobileNumber = "", Status = ContactStatus.Approved, OwnerId = adminId }, new Contact { Name = "汪淼", Address = "文二路", City = "杭州市", Province = "浙江省", Zip = "310000", Email = "*****@*****.**", MobileNumber = "", Status = ContactStatus.Submitted, OwnerId = adminId }, new Contact { Name = "史强", Address = "文三路", City = "杭州市", Province = "浙江省", Zip = "310000", Email = "*****@*****.**", MobileNumber = "", Status = ContactStatus.Rejected, OwnerId = adminId }, new Contact { Name = "罗辑", Address = "天目山路", City = "杭州市", Province = "浙江省", Zip = "310000", Email = "*****@*****.**", MobileNumber = "", Status = ContactStatus.Submitted, OwnerId = adminId }, new Contact { Name = "章北海", Address = "万塘路", City = "杭州市", Province = "浙江省", Zip = "310000", Email = "*****@*****.**", MobileNumber = "", OwnerId = adminId } ); context.SaveChanges(); }