Example #1
0
        public async Task SeedAsync()
        {
            await _context.Database.MigrateAsync().ConfigureAwait(false);

            if (!await _accountManager.AnyUserAsync(null))
            {
                _logger.LogInformation("Generating inbuilt accounts");

                const string clientRoleName           = "Client";
                const string chiefAuditorRoleName     = "ChiefAutditor";
                const string auditFacilitatorRoleName = "AuditFacilitator";
                const string adminRoleName            = "STPSystemAdmin";
                const string techRoleName             = "STPAMTech";

                await EnsureRoleAsync(adminRoleName, "STPSystemAdmin", ApplicationPermissions.GetAllSTPSystemAdminValues());
                await EnsureRoleAsync(clientRoleName, "Client", ApplicationPermissions.GetClientPermissionValues());
                await EnsureRoleAsync(chiefAuditorRoleName, "ChiefAutditor", ApplicationPermissions.GetChiefAutditorPermissionValues());
                await EnsureRoleAsync(auditFacilitatorRoleName, "AuditFacilitator", ApplicationPermissions.GetAuditFacilitatorPermissionValues());
                await EnsureRoleAsync(techRoleName, "STPAMTech", new string[] { });

                await CreateUserAsync("STPSystemAdmin", "Stp123$", "STP System Admin", "*****@*****.**", "+1 (123) 000-0000", new string[] { adminRoleName });
                await CreateUserAsync("Client", "Stp123$", "Client", "*****@*****.**", "+1 (123) 000-0001", new string[] { clientRoleName });
                await CreateUserAsync("ChiefAutditor", "Stp123$", "Chief Autditor", "*****@*****.**", "+1 (123) 000-0001", new string[] { chiefAuditorRoleName });
                await CreateUserAsync("AuditFacilitator", "Stp123$", "Audit Facilitator", "*****@*****.**", "+1 (123) 000-0001", new string[] { auditFacilitatorRoleName });
                await CreateUserAsync("STPAMTech", "Stp123$", "STP AM / Tech", "*****@*****.**", "+1 (123) 000-0001", new string[] { techRoleName });

                _logger.LogInformation("Inbuilt account generation completed");
            }
        }
        /// <summary>
        /// Seed DB per tenant
        /// </summary>
        /// <param name="tenantName"></param>
        /// <returns></returns>
        public async Task SeedAsync(int tenantId, string adminPassword = "******")//string tenantName)
        {
            //await _context.Database.EnsureCreatedAsync();

            //Apply migrations: tenant DB witll be created, then migrations applied
            await _context.Database.MigrateAsync().ConfigureAwait(false);

            using (var transaction = _context.Database.BeginTransaction())
            {
                //1.Create 'predefined roles' in the Tenant DB
                //Create 'internal' roles with related permissions
                await EnsureRoleAsync(adminRoleName, "Tenant admin role", tenantId, ApplicationPermissions.GetAllPermissionValues());
                await EnsureRoleAsync(managerRoleName, "Manager role of the tenant", tenantId, ApplicationPermissions.GetAllPermissionValues());
                await EnsureRoleAsync(consultantRoleName, "Consultant role of the tenat", tenantId, ApplicationPermissions.GetConsultantPermissionValues());
                await EnsureRoleAsync(supportRoleName, "Support contact role of the tenant", tenantId, new string[] { });     //TODO: 'Support contact' permissions
                await EnsureRoleAsync(communicationRoleName, "Communication role of the tenant", tenantId, new string[] { }); //TODO: 'Support role' permissions

                //await EnsureRoleAsync(userRoleName, "'Simple user' role of tenant", tenantId, new string[] { });//TODO: 'Simple user' permissions

                await EnsureRoleAsync(candidateRoleName, "Candidate - 'external role' of tenant. Candidate not exepted offer yet", tenantId, ApplicationPermissions.GetCandidatePermissionValues()); //TODO: candidate permissions
                await EnsureRoleAsync(TWRoleName, "TW - temporary worker 'internal role' of tenant", tenantId, new string[] { });                                                                    //TODO: TW permissions
                await EnsureRoleAsync(PLURoleName, "PLU - permanent worker 'interanl role' of tenant", tenantId, new string[] { });                                                                  //TODO: PLU permissions
                await EnsureRoleAsync(contractorRoleName, "Contractor - 'external role' of tenant", tenantId, new string[] { });                                                                     //TODO: contractor permissions

                await EnsureRoleAsync(clientRoleName, "Client - 'external role' of the tenant. Who are looking for workers", tenantId, ApplicationPermissions.GetClientPermissionValues());

                //2. Create predefined users
                //NOTE: test users per role (to test logins under different accounts)
                await CreateTestUsers(tenantId, adminPassword);

                transaction.Commit();
            }
        }