// GET: Jobs/Create public ActionResult Create() { CreateTenantInputDto createtenantinputdto = new CreateTenantInputDto(); return View(createtenantinputdto); }
public async Task CreateTenant(CreateTenantInputDto input) { //Create tenant var tenant = new Tenant(input.TenancyName, input.Name); var defaultEdition = await _editionManager.FindByNameAsync(EditionManager.DefaultEditionName); if (defaultEdition != null) { tenant.EditionId = defaultEdition.Id; } CheckErrors(await TenantManager.CreateAsync(tenant)); await CurrentUnitOfWork.SaveChangesAsync(); //To get new tenant's id. //We are working entities of new tenant, so changing tenant filter using (CurrentUnitOfWork.SetFilterParameter(AbpDataFilters.MayHaveTenant, AbpDataFilters.Parameters.TenantId, tenant.Id)) { //Create static roles for new tenant CheckErrors(await _roleManager.CreateStaticRoles(tenant.Id)); await CurrentUnitOfWork.SaveChangesAsync(); //To get static role ids //grant all permissions to admin role //TODO: assign all permissions to admin role. cant get this working. _roleManager.Roles returns empty collection /// remove for now - there are no permissions implemented var adminRole = _roleManager.Roles.Single(r => r.Name == StaticRoleNames.Tenants.Admin); await _roleManager.GrantAllPermissionsAsync(adminRole); //TODO: End of assign all permissions to admin role. cant get this working. _roleManager.Roles returns empty collection //Create admin user for the tenant var adminUser = User.CreateTenantAdminUser(tenant.Id, input.AdminEmailAddress, User.DefaultPassword); CheckErrors(await UserManager.CreateAsync(adminUser)); await CurrentUnitOfWork.SaveChangesAsync(); //To get admin user's id //Assign admin user to role! //CheckErrors(await UserManager.AddToRoleAsync(adminUser.Id, adminRole.Name)); CheckErrors(await UserManager.AddToRoleAsync(adminUser.Id, adminRole.Name)); await CurrentUnitOfWork.SaveChangesAsync(); } }