public List <User> GetRandomUsers(int userCount, int tenantId) { var users = new List <User>(); var randomNames = MyRandomHelper.GenerateRandomizedList(Names); for (var i = 0; i < userCount && i < randomNames.Count; i++) { users.Add(CreateUser(tenantId, randomNames[i])); } return(users); }
private async Task BuildForInternalAsync(Tenant tenant) { //Create Organization Units var organizationUnits = new List <OrganizationUnit>(); var producing = await CreateAndSaveOrganizationUnit(organizationUnits, tenant, "Producing"); var researchAndDevelopment = await CreateAndSaveOrganizationUnit(organizationUnits, tenant, "Research & Development", producing); var ivrProducts = await CreateAndSaveOrganizationUnit(organizationUnits, tenant, "IVR Related Products", researchAndDevelopment); var voiceTech = await CreateAndSaveOrganizationUnit(organizationUnits, tenant, "Voice Technologies", researchAndDevelopment); var inhouseProjects = await CreateAndSaveOrganizationUnit(organizationUnits, tenant, "Inhouse Projects", researchAndDevelopment); var qualityManagement = await CreateAndSaveOrganizationUnit(organizationUnits, tenant, "Quality Management", producing); var testing = await CreateAndSaveOrganizationUnit(organizationUnits, tenant, "Testing", producing); var selling = await CreateAndSaveOrganizationUnit(organizationUnits, tenant, "Selling"); var marketing = await CreateAndSaveOrganizationUnit(organizationUnits, tenant, "Marketing", selling); var sales = await CreateAndSaveOrganizationUnit(organizationUnits, tenant, "Sales", selling); var custRelations = await CreateAndSaveOrganizationUnit(organizationUnits, tenant, "Customer Relations", selling); var supporting = await CreateAndSaveOrganizationUnit(organizationUnits, tenant, "Supporting"); var buying = await CreateAndSaveOrganizationUnit(organizationUnits, tenant, "Buying", supporting); var humanResources = await CreateAndSaveOrganizationUnit(organizationUnits, tenant, "Human Resources", supporting); //Create users var users = _randomUserGenerator.GetRandomUsers(RandomHelper.GetRandom(12, 26), tenant.Id); foreach (var user in users) { //Create the user await _userManager.CreateAsync(user); await CurrentUnitOfWork.SaveChangesAsync(); //Add to roles _userManager.AddToRole(user.Id, StaticRoleNames.Tenants.User); //Add to OUs var randomOus = MyRandomHelper.GenerateRandomizedList(organizationUnits).Take(RandomHelper.GetRandom(0, 3)); foreach (var ou in randomOus) { await _userManager.AddToOrganizationUnitAsync(user, ou); } //Set profile picture if (RandomHelper.GetRandom(100) < 70) //A user will have a profile picture in 70% probability. { await SetRandomProfilePictureAsync(user); } } //Set a picture to admin! var admin = _userManager.FindByName(User.AdminUserName); await SetRandomProfilePictureAsync(admin); }