public async Task SeedAsync() { await _context.Database.MigrateAsync().ConfigureAwait(false); // await _context.Database.EnsureCreatedAsync(); if (!await _context.Users.AnyAsync()) { _logger.LogInformation("Generating inbuilt accounts"); const string adminRoleName = "super administrator"; const string groupAdminRoleName = "group administrator"; const string userRoleName = "user"; const string respondentRoleName = "respondent"; await EnsureRoleAsync(adminRoleName, "Super administrator", 0, ApplicationPermissions.GetAllPermissionValues()); await EnsureRoleAsync(groupAdminRoleName, "Group administrator", 1, ApplicationPermissions.GetAllGroupPermissionValues()); await EnsureRoleAsync(userRoleName, "Basic user", 2, ApplicationPermissions.GetAdministrativePermissionValues()); await EnsureRoleAsync(respondentRoleName, "Survey Respondent", 3, new string[] { }); var adminAccounts = _configuration.GetSection("AdminAccounts").GetChildren(); _logger.LogInformation("Creating admin accounts."); if (adminAccounts.Count() == 0) { _logger.LogWarning("No admin accounts exist."); // throw new Exception("No admin accounts in configuration."); } foreach (var section in adminAccounts) { var username = section.GetValue <string>("Username"); var password = section.GetValue <string>("Password"); await CreateUserAsync(username, password, "Inbuilt Administrator", "*****@*****.**", "+1 (123) 000-0000", new string[] { adminRoleName }); } //await CreateUserAsync("admin2", "tempP@ss456", "Inbuilt Administrator", "*****@*****.**", "+1 (123) 000-0000", new string[] { adminRoleName }); //await CreateUserAsync("user", "tempP@ss789", "Inbuilt Standard User", "*****@*****.**", "+1 (123) 000-0001", new string[] { userRoleName }); //await CreateUserAsync("respondent", "@ss789", "Respondent User", "*****@*****.**", "+1 (123) 000-0001", new string[] { respondentRoleName }); //smto = await CreateUserAsync("smto", "tempP@ss789", "Inbuilt Standard User", "*****@*****.**", "+1 (123) 000-0001", new string[] { userRoleName }); //tts = await CreateUserAsync("tts", "tempP@ss789", "Inbuilt Standard User", "*****@*****.**", "+1 (123) 000-0001", new string[] { userRoleName }); _logger.LogInformation("Inbuilt account generation completed"); } if (!await _context.UserGroups.AnyAsync()) { _logger.LogInformation("Seeding initial data"); UserGroup TTS = new UserGroup() { Name = "TTS", Members = new List <GroupMember>(), ApiKeySettings = new ApiKeys() { MailgunApiKey = "TTSMail", GoogleMapsApiKey = "TTSGoogle", MapBoxApiKey = "TTSMapbox" } }; UserGroup SMTO = new UserGroup() { Name = "StudentMove", Members = new List <GroupMember>(), ApiKeySettings = new ApiKeys() { MailgunApiKey = "SMTOMail", GoogleMapsApiKey = "SMTOGoogle", MapBoxApiKey = "SMTOMapbox" } }; _context.UserGroups.Add(TTS); _context.UserGroups.Add(SMTO); /*Survey TTSSurvey; * using (StreamReader r = new StreamReader("structure.json")) * { * var jsonFile = r.ReadToEnd(); * TTSSurvey = JsonConvert.DeserializeObject<Survey>(jsonFile, new JsonSerializerSettings { PreserveReferencesHandling = PreserveReferencesHandling.Objects}); * } * * _context.Surveys.Add(TTSSurvey);*/ await _context.SaveChangesAsync(); _logger.LogInformation("Seeding initial data completed"); } }