private async Task SeedDemoDataAsync() { if ((await _userManager.FindByNameAsync(DefaultUserNames.User)) == null) { await CreateUserAsync(DefaultUserNames.User, "user123", "User", "Blazor", "*****@*****.**", "+1 (123) 456-7890"); } if (_tenantStoreDbContext.TenantInfo.Count() < 2) { _tenantStoreDbContext.TenantInfo.Add(new TenantInfo() { Id = "tenant1", Identifier = "tenant1.local", Name = "Microsoft Inc." }); _tenantStoreDbContext.TenantInfo.Add(new TenantInfo() { Id = "tenant2", Identifier = "tenant2.local", Name = "Contoso Corp." }); _tenantStoreDbContext.SaveChanges(); } ApplicationUser user = await _userManager.FindByNameAsync(DefaultUserNames.User); if (!_context.UserProfiles.Any()) { _context.UserProfiles.Add(new UserProfile { UserId = user.Id, ApplicationUser = user, Count = 2, IsNavOpen = true, LastPageVisited = "/dashboard", IsNavMinified = false, LastUpdatedDate = DateTime.Now }); } if (!_context.Todos.Any()) { var rnd = new Random(); var fruits = new string[] { "apples", "pears", "peaches", "oranges" }; var users = _context.Users.ToArray(); for (int i = 0; i < 1000; i++) { _context.Todos.Add( new Todo { IsCompleted = false, Title = $"Buy {rnd.Next(2, 5)} {fruits[rnd.Next(fruits.Length)]}", CreatedById = users[rnd.Next(users.Length)].Id } ); } } if (!_context.ApiLogs.Any()) { _context.ApiLogs.AddRange( new ApiLogItem { RequestTime = DateTime.Now, ResponseMillis = 30, StatusCode = 200, Method = "Get", Path = "/api/seed", QueryString = "", RequestBody = "", ResponseBody = "", IPAddress = "::1", ApplicationUserId = user.Id }, new ApiLogItem { RequestTime = DateTime.Now, ResponseMillis = 30, StatusCode = 200, Method = "Get", Path = "/api/seed", QueryString = "", RequestBody = "", ResponseBody = "", IPAddress = "::1", ApplicationUserId = user.Id } ); } _context.SaveChanges(); }
private async Task SeedDemoDataAsync() { if ((await _userManager.FindByNameAsync(DefaultUserNames.User)) == null) { await EnsureRoleAsync(userRoleName, "Default user", new string[] { }); await CreateUserAsync(DefaultUserNames.User, "user123", DefaultRoleNames.User, "Blazor", "User Blazor", "*****@*****.**", "+1 (123) 456-7890", new string[] { userRoleName }); } if (_tenantStoreDbContext.TenantInfo.Count() < 2) { _tenantStoreDbContext.TenantInfo.Add(new TenantInfo("tenant1", "tenant1.local", "Microsoft Inc.", null, null)); _tenantStoreDbContext.TenantInfo.Add(new TenantInfo("tenant2", "tenant2.local", "Contoso Corp.", null, null)); _tenantStoreDbContext.SaveChanges(); } ApplicationUser user = await _userManager.FindByNameAsync(DefaultUserNames.User); if (!_context.UserProfiles.Any()) { _context.UserProfiles.Add(new UserProfile { UserId = user.Id, ApplicationUser = user, Count = 2, IsNavOpen = true, LastPageVisited = "/dashboard", IsNavMinified = false, LastUpdatedDate = DateTime.Now }); } if (!_context.Todos.Any()) { _context.Todos.AddRange( new Todo { IsCompleted = false, Title = "Test BlazorBoilerplate" }, new Todo { IsCompleted = false, Title = "Test BlazorBoilerplate 1", } ); } if (!_context.ApiLogs.Any()) { _context.ApiLogs.AddRange( new ApiLogItem { RequestTime = DateTime.Now, ResponseMillis = 30, StatusCode = 200, Method = "Get", Path = "/api/seed", QueryString = "", RequestBody = "", ResponseBody = "", IPAddress = "::1", ApplicationUserId = user.Id }, new ApiLogItem { RequestTime = DateTime.Now, ResponseMillis = 30, StatusCode = 200, Method = "Get", Path = "/api/seed", QueryString = "", RequestBody = "", ResponseBody = "", IPAddress = "::1", ApplicationUserId = user.Id } ); } _context.SaveChanges(); }