public async Task SeedAsync()
        {
            await _context.Database.MigrateAsync().ConfigureAwait(false);

            if (!await _context.Users.AnyAsync())
            {
                _logger.LogInformation("Generating inbuilt accounts...");

                await EnsureRoleAsync(
                    RoleConstants.AdministratorRoleName, ApplicationPermissions.GetAdministrativePermissionValues());
                await EnsureRoleAsync(
                    RoleConstants.DoctorRoleName, ApplicationPermissions.GetDoctorPermissionValues());
                await EnsureRoleAsync(
                    RoleConstants.ReceptionistRoleName, ApplicationPermissions.GetReceptionistPermissionValues());

                await CreateUserAsync(
                    "admin", "admin@123", "Quản trị viên", "*****@*****.**", "0999999999",
                    new string[] { RoleConstants.AdministratorRoleName });

                _logger.LogInformation("Inbuilt account generation completed.");
            }
        }
예제 #2
0
        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");
            }
        }
예제 #3
0
        public async Task SeedAsync()
        {
            await this.context.Database.MigrateAsync().ConfigureAwait(false);

            if (!await this.context.Users.AnyAsync())
            {
                await this.EnsureRoleAsync(ApplicationRole.AdminRoleName, "Default administrator", ApplicationPermissions.GetAdministrativePermissionValues());

                await this.EnsureRoleAsync(ApplicationRole.UserRoleName, "Default user", ApplicationPermissions.GetStanderdMemberPermissionValues());

                await this.CreateUserAsync("*****@*****.**", "tempP@ssaw0rd", "Adam", "Adam", "+962000000000", new string[] { ApplicationRole.AdminRoleName });
            }

            if (!await this.context.FamilyMembers.AnyAsync())
            {
                await this.InitializeFamilyMembers();
            }

            if (!await this.context.LookupItems.AnyAsync())
            {
                await this.CreateCountriesAsync();

                await this.CreateHoroscpesAsync();
            }
        }