public override async Task <IList <Claim> > GetClaimsAsync(IdentityUserNav <TKey> user, CancellationToken cancellationToken = default) { ThrowIfDisposed(); if (user == null) { throw new ArgumentNullException(nameof(user)); } return(await UserClaims.Where(uc => uc.UserId.Equals(user.Id)).Select(c => c.ToClaim()).ToListAsync(cancellationToken)); }
//protected Task SaveChanges(CancellationToken cancellationToken) => AutoSaveChanges ? Context.SaveChangesAsync(cancellationToken) : Task.CompletedTask; public override async Task <IdentityResult> CreateAsync(IdentityUserNav <TKey> user, CancellationToken cancellationToken = default) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); if (user == null) { throw new ArgumentNullException(nameof(user)); } await DataConnection.InsertAsync(user); //await SaveChanges(cancellationToken); return(IdentityResult.Success); }
public override async Task <IList <UserLoginInfo> > GetLoginsAsync(IdentityUserNav <TKey> user, CancellationToken cancellationToken = default) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); if (user == null) { throw new ArgumentNullException(nameof(user)); } var userId = user.Id; return(await UserLogins.Where(l => l.UserId.Equals(userId)) .Select(l => new UserLoginInfo(l.LoginProvider, l.ProviderKey, l.ProviderDisplayName)).ToListAsync(cancellationToken)); }
public override async Task RemoveLoginAsync(IdentityUserNav <TKey> user, string loginProvider, string providerKey, CancellationToken cancellationToken = default) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); if (user == null) { throw new ArgumentNullException(nameof(user)); } var entry = await FindUserLoginAsync(user.Id, loginProvider, providerKey, cancellationToken); if (entry != null) { UserLogins.DataContext.Delete(entry); } }
public override Task AddLoginAsync(IdentityUserNav <TKey> user, UserLoginInfo login, CancellationToken cancellationToken = default) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); if (user == null) { throw new ArgumentNullException(nameof(user)); } if (login == null) { throw new ArgumentNullException(nameof(login)); } UserLogins.DataContext.Insert(CreateUserLogin(user, login)); return(Task.FromResult(false)); }
public override async Task <IList <string> > GetRolesAsync(IdentityUserNav <TKey> user, CancellationToken cancellationToken = default) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); if (user == null) { throw new ArgumentNullException(nameof(user)); } var userId = user.Id; var query = from userRole in UserRoles join role in Roles on userRole.RoleId equals role.Id where userRole.UserId.Equals(userId) select role.Name; return(await query.ToListAsync(cancellationToken)); }
public override async Task <IdentityResult> DeleteAsync(IdentityUserNav <TKey> user, CancellationToken cancellationToken = default) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); if (user == null) { throw new ArgumentNullException(nameof(user)); } await DataConnection.DeleteAsync(user); //try { // await SaveChanges(cancellationToken); //} catch (DbUpdateConcurrencyException) { // return IdentityResult.Failed(ErrorDescriber.ConcurrencyFailure()); //} return(IdentityResult.Success); }
public override Task AddClaimsAsync(IdentityUserNav <TKey> user, IEnumerable <Claim> claims, CancellationToken cancellationToken = default) { ThrowIfDisposed(); if (user == null) { throw new ArgumentNullException(nameof(user)); } if (claims == null) { throw new ArgumentNullException(nameof(claims)); } foreach (var claim in claims) { UserClaims.DataContext.Insert(CreateUserClaim(user, claim)); } return(Task.FromResult(false)); }
public override async Task AddToRoleAsync(IdentityUserNav <TKey> user, string normalizedRoleName, CancellationToken cancellationToken = default) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); if (user == null) { throw new ArgumentNullException(nameof(user)); } if (string.IsNullOrWhiteSpace(normalizedRoleName)) { throw new ArgumentException(Resources.ValueCannotBeNullOrEmpty, nameof(normalizedRoleName)); } var roleEntity = await FindRoleAsync(normalizedRoleName, cancellationToken); if (roleEntity == null) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.RoleNotFound, normalizedRoleName)); } UserRoles.DataContext.Insert(CreateUserRole(user, roleEntity)); }
public override async Task RemoveClaimsAsync(IdentityUserNav <TKey> user, IEnumerable <Claim> claims, CancellationToken cancellationToken = default) { ThrowIfDisposed(); if (user == null) { throw new ArgumentNullException(nameof(user)); } if (claims == null) { throw new ArgumentNullException(nameof(claims)); } foreach (var claim in claims) { var matchedClaims = await UserClaims.Where(uc => uc.UserId.Equals(user.Id) && uc.ClaimValue == claim.Value && uc.ClaimType == claim.Type).ToListAsync(cancellationToken); foreach (var c in matchedClaims) { UserClaims.DataContext.Delete(c); } } }
public override async Task <bool> IsInRoleAsync(IdentityUserNav <TKey> user, string normalizedRoleName, CancellationToken cancellationToken = default) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); if (user == null) { throw new ArgumentNullException(nameof(user)); } if (string.IsNullOrWhiteSpace(normalizedRoleName)) { throw new ArgumentException(Resources.ValueCannotBeNullOrEmpty, nameof(normalizedRoleName)); } var role = await FindRoleAsync(normalizedRoleName, cancellationToken); if (role != null) { var userRole = await FindUserRoleAsync(user.Id, role.Id, cancellationToken); return(userRole != null); } return(false); }
public override async Task ReplaceClaimAsync(IdentityUserNav <TKey> user, Claim claim, Claim newClaim, CancellationToken cancellationToken = default) { ThrowIfDisposed(); if (user == null) { throw new ArgumentNullException(nameof(user)); } if (claim == null) { throw new ArgumentNullException(nameof(claim)); } if (newClaim == null) { throw new ArgumentNullException(nameof(newClaim)); } var matchedClaims = await UserClaims.Where(uc => uc.UserId.Equals(user.Id) && uc.ClaimValue == claim.Value && uc.ClaimType == claim.Type).ToListAsync(cancellationToken); foreach (var matchedClaim in matchedClaims) { matchedClaim.ClaimValue = newClaim.Value; matchedClaim.ClaimType = newClaim.Type; } }
public override async Task RemoveFromRoleAsync(IdentityUserNav <TKey> user, string normalizedRoleName, CancellationToken cancellationToken = default) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); if (user == null) { throw new ArgumentNullException(nameof(user)); } if (string.IsNullOrWhiteSpace(normalizedRoleName)) { throw new ArgumentException(Resources.ValueCannotBeNullOrEmpty, nameof(normalizedRoleName)); } var roleEntity = await FindRoleAsync(normalizedRoleName, cancellationToken); if (roleEntity != null) { var userRole = await FindUserRoleAsync(user.Id, roleEntity.Id, cancellationToken); if (userRole != null) { UserRoles.DataContext.Delete(userRole); } } }
protected override Task <IdentityUserTokenNav <TKey> > FindTokenAsync(IdentityUserNav <TKey> user, string loginProvider, string name, CancellationToken cancellationToken) => UserTokens.FirstOrDefaultAsync(x => x.UserId.Equals(user.Id) && x.LoginProvider.Equals(loginProvider, StringComparison.OrdinalIgnoreCase) && x.Name.Equals(name, StringComparison.OrdinalIgnoreCase), cancellationToken);
protected override Task <IdentityUserTokenNav <TKey> > FindTokenAsync(IdentityUserNav <TKey> user, string loginProvider, string name, CancellationToken cancellationToken) => (from ut in UserTokens where ut.UserId.Equals(user.Id) && ut.LoginProvider.Equals(loginProvider, StringComparison.OrdinalIgnoreCase) && ut.Name.Equals(name, StringComparison.OrdinalIgnoreCase) select ut).FirstOrDefaultAsync(cancellationToken);