public async Task AddToRoleAsync(UserAccount user, string roleName, CancellationToken cancellationToken) { var role = await _roleStore.FindByNameAsync(roleName, new CancellationToken()); _userRoleRepository.CreatNewElement(new UserRoleModel { RoleId = role.Id, UserId = user.Id.Value }); user.UserRoles.Add(roleName); }
public async Task RoleStore_create_find_by_name() { var role = _roleTestFactory.CreateRole(); await _roleStore.CreateAsync(role, default(CancellationToken)); await _roleStore.SetNormalizedRoleNameAsync(role, role.Name, default(CancellationToken)); var fetchedRole = await _roleStore.FindByNameAsync(role.Name, default(CancellationToken)); role.Name.ShouldMatch(fetchedRole.Name); }
public async Task AddToRoleAsync(TApplicationUser user, string roleName) { var roleEntity = await roleStore.FindByNameAsync(roleName); if (roleEntity != null) { var userRole = new TApplicationUserRole { UserId = user.Id, RoleId = roleEntity.Id }; await userRoleRepository.Add(userRole.MapTo <TUserRole>(), session); } }
public async Task AddToRoleAsync(ApplicationUser user, string roleName, CancellationToken cancellationToken) { string normalizedRoleName = roleName.ToUpperInvariant(); ApplicationRole role = await _roleStore.FindByNameAsync(normalizedRoleName, cancellationToken); var userRole = new ApplicationUserRole { ApplicationUserId = user.Id, ApplicationRoleId = role.Id }; _dbContext.Add(userRole); await _dbContext.SaveChangesAsync(cancellationToken); }
public async Task AddToRoleAsync(TUser user, string roleName, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); var role = await _roleStore.FindByNameAsync(roleName, cancellationToken); if (role == null) { return; } user.Roles.Add(role.Id); await Update(user, x => x.Roles, user.Roles); }
public async Task AddToRoleAsync(TUser user, string roleName, CancellationToken cancellationToken) { TRole role = await _roleStore.FindByNameAsync(roleName, cancellationToken); if (role == null) { return; } TUserInRole userInRole = _objectProvider.CreateObject <TUserInRole>(); SetProperty(userInRole, _options.RoleProperty, role); SetProperty(userInRole, _options.UserProperty, user); _usersInRole.Where(x => x == userInRole).Save(); }
public async Task AddToRoleAsync(TUser user, string roleName, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); if (user == null) { throw new ArgumentNullException(nameof(user)); } if (roleName == null) { throw new ArgumentNullException(nameof(roleName)); } // Check if the given role name exists TRole foundRole = await roleStore.FindByNameAsync(roleName, cancellationToken); if (foundRole == null) { throw new ArgumentException(nameof(roleName)); } user.Roles.Add(foundRole); }
public async Task AddToRoleAsync(TUser user, string roleName, CancellationToken cancellationToken = default(CancellationToken)) { cancellationToken.ThrowIfCancellationRequested(); var roleEntity = await roleStore.FindByNameAsync(roleName, cancellationToken); if (roleEntity != null) { var userRole = new TUserRole() { UserId = user.Id, RoleId = roleEntity.Id }; var newRole = await userRoleRepository.Add(userRole, session); user.UserRoles.Add(newRole); } }
public async Task AddToRoleAsync(TUser user, string roleName, CancellationToken cancellationToken) { if (user == null) { throw new ArgumentNullException(nameof(user)); } cancellationToken.ThrowIfCancellationRequested(); var role = await _roleStore.FindByNameAsync(roleName, cancellationToken).ConfigureAwait(true); if (role == null) { return; } user.Roles.Add(role.Id.ToString()); await UpdateAsync(user, x => x.Roles, user.Roles, cancellationToken).ConfigureAwait(false); }
public async Task AddToRoleAsync(User user, string roleName, CancellationToken cancellationToken) { var role = await _rolesStore.FindByNameAsync(roleName, cancellationToken); if (role == null) { throw new Exception($"Role does not exist {roleName}"); } await _repo.ExecuteAsync( _helper.GetAddUserToRoleSql(role), cancellationToken, new { userId = user.Id, role.Id }); }
public async Task <ApplicationRole> FindByNameAsync(string normalizedRoleName, CancellationToken cancellationToken) { return(await roleStore.FindByNameAsync(normalizedRoleName, cancellationToken)); }
public async Task AddToRoleAsync(User user, string roleName, CancellationToken cancellationToken) { var role = await roleStore.FindByNameAsync(roleName, cancellationToken); user.AddRole(role); }
public Task <IdentityRole> FindRoleByNameAsync(string roleName) { return(_roleStore.FindByNameAsync(roleName, CancellationToken.None)); }