Exemplo n.º 1
0
        public async Task <IActionResult> ManageRoles(List <string> userIds, string roleName)
        {
            foreach (var userId in userIds)
            {
                BTUser user = await _context.Users.FindAsync(userId);

                if (!await _roleService.IsUserInRoleAsync(user, roleName))
                {
                    var userRoles = await _roleService.ListUserRolesAsync(user);

                    foreach (var role in userRoles)
                    {
                        await _roleService.RemoveUserFromRoleAsync(user, role);
                    }
                    await _roleService.AddUserToRoleAsync(user, roleName);
                }
            }
            return(View());
        }
Exemplo n.º 2
0
        public async Task <string> InviteWizardAsync(InviteViewModel inviteViewModel)
        {
            var companyId = await CreateCompanyAsync(inviteViewModel.CompanyName, inviteViewModel.CompanyDescription);

            var user = new BTUser
            {
                Email          = inviteViewModel.Email,
                UserName       = inviteViewModel.Email,
                FirstName      = inviteViewModel.FirstName,
                LastName       = inviteViewModel.LastName,
                EmailConfirmed = true,
                CompanyId      = companyId
            };

            await _userManager.CreateAsync(user, "Abc&123!");

            await _roleService.AddUserToRoleAsync(user, Roles.Admin.ToString());

            var projectId = await CreateProjectAsync(inviteViewModel.ProjectName, inviteViewModel.ProjectDescription, companyId);

            await _projectService.AddUserToProjectAsync(user.Id, projectId);

            return(user.Id);
        }