Add support for documents with and Id of type ObjectId.
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AspNetCore.Identity.MongoDbCore" Version="1.0.7" />
|
||||
<PackageReference Include="AspNetCore.Identity.MongoDbCore" Version="1.0.8" />
|
||||
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.1.1" />
|
||||
<PackageReference Include="Microsoft.AspNetCore" Version="2.0.1" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.0.1" />
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
<PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.0.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="2.0.1" />
|
||||
<PackageReference Include="MongoDB.Driver" Version="2.5.0" />
|
||||
<PackageReference Include="MongoDbGenericRepository" Version="1.3.4" />
|
||||
<PackageReference Include="MongoDbGenericRepository" Version="1.3.6" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<package >
|
||||
<metadata>
|
||||
<id>AspNetCore.Identity.MongoDbCore</id>
|
||||
<version>1.0.7</version>
|
||||
<version>1.0.8</version>
|
||||
<title>AspNetCore.Identity.MongoDbCore</title>
|
||||
<authors>Alexandre Spieser</authors>
|
||||
<owners>Alexandre Spieser</owners>
|
||||
@@ -10,14 +10,14 @@
|
||||
<projectUrl>https://github.com/alexandre-spieser/AspNetCore.Identity.MongoDbCore</projectUrl>
|
||||
<requireLicenseAcceptance>false</requireLicenseAcceptance>
|
||||
<description>A MongoDb UserStore and RoleStore adapter for Microsoft.AspNetCore.Identity 2.0.</description>
|
||||
<releaseNotes>MongoDB 3.6 Support, Identity 2.0.1 upgrade.</releaseNotes>
|
||||
<copyright>Copyright 2017 (c) Alexandre Spieser. All rights reserved.</copyright>
|
||||
<releaseNotes>Added support for documents with an Id of type ObjectId.</releaseNotes>
|
||||
<copyright>Copyright 2018 (c) Alexandre Spieser. All rights reserved.</copyright>
|
||||
<tags>aspnetcore mongo mongodb identity membership</tags>
|
||||
<dependencies>
|
||||
<dependency id="Microsoft.AspNetCore.Identity" version="2.0.1" />
|
||||
<dependency id="Microsoft.Extensions.Identity.Stores" version="2.0.1" />
|
||||
<dependency id="MongoDB.Driver" version="2.5.0" />
|
||||
<dependency id="MongoDbGenericRepository" version="1.3.4" />
|
||||
<dependency id="MongoDbGenericRepository" version="1.3.6" />
|
||||
</dependencies>
|
||||
</metadata>
|
||||
<files>
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
using MongoDB.Bson;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace AspNetCore.Identity.MongoDbCore.Extensions
|
||||
{
|
||||
/// <summary>
|
||||
/// A set of extensions for string.
|
||||
/// </summary>
|
||||
public static class StringExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts the provided <paramref name="id"/> to a strongly typed key object.
|
||||
/// </summary>
|
||||
/// <typeparam name="TKey"></typeparam>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public static TKey ToTKey<TKey>(this string id)
|
||||
{
|
||||
if (id == null)
|
||||
{
|
||||
return default(TKey);
|
||||
}
|
||||
var typeOfKey = typeof(TKey);
|
||||
if (typeOfKey.Name != "ObjectId")
|
||||
{
|
||||
return (TKey)TypeDescriptor.GetConverter(typeOfKey).ConvertFromInvariantString(id);
|
||||
}
|
||||
return (TKey)(object)(new ObjectId(id));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
using AspNetCore.Identity.MongoDbCore.Interfaces;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using MongoDbGenericRepository.Models;
|
||||
using MongoDbGenericRepository.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
@@ -56,33 +57,6 @@ namespace AspNetCore.Identity.MongoDbCore.Models
|
||||
public class MongoIdentityRole<TKey> : IdentityRole<TKey>, IDocument<TKey>, IClaimHolder
|
||||
where TKey : IEquatable<TKey>
|
||||
{
|
||||
|
||||
private void InitializeFields()
|
||||
{
|
||||
Version = 1;
|
||||
Claims = new List<MongoClaim>();
|
||||
Guid guidValue = Guid.NewGuid();
|
||||
var idTypeName = typeof(TKey).Name;
|
||||
switch (idTypeName)
|
||||
{
|
||||
case "Guid":
|
||||
Id = (TKey)(object)guidValue;
|
||||
break;
|
||||
case "Int16":
|
||||
Id = (TKey)(object)GlobalVariables.Random.Next(1, short.MaxValue);
|
||||
break;
|
||||
case "Int32":
|
||||
Id = (TKey)(object)GlobalVariables.Random.Next(1, int.MaxValue);
|
||||
break;
|
||||
case "Int64":
|
||||
Id = (TKey)(object)(GlobalVariables.Random.NextLong(1, long.MaxValue));
|
||||
break;
|
||||
case "String":
|
||||
Id = (TKey)(object)guidValue.ToString();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The constructor for a <see cref="MongoIdentityRole{TKey}"/>
|
||||
/// </summary>
|
||||
@@ -101,6 +75,16 @@ namespace AspNetCore.Identity.MongoDbCore.Models
|
||||
InitializeFields();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initialize the field of the MongoIdentityRole
|
||||
/// </summary>
|
||||
protected virtual void InitializeFields()
|
||||
{
|
||||
Version = 1;
|
||||
Claims = new List<MongoClaim>();
|
||||
Id = IdGenerator.GetId<TKey>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The constructor for a <see cref="MongoIdentityRole{TKey}"/>, taking a role name and a primary key value.
|
||||
/// </summary>
|
||||
|
||||
@@ -6,6 +6,7 @@ using MongoDB.Driver;
|
||||
using AspNetCore.Identity.MongoDbCore.Interfaces;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using AspNetCore.Identity.MongoDbCore.Extensions;
|
||||
using MongoDbGenericRepository.Utils;
|
||||
|
||||
namespace AspNetCore.Identity.MongoDbCore.Models
|
||||
{
|
||||
@@ -134,7 +135,19 @@ namespace AspNetCore.Identity.MongoDbCore.Models
|
||||
UserName = userName ?? throw new ArgumentNullException(nameof(userName));
|
||||
SetVersion(1);
|
||||
InitializeFields();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initialize the field of the MongoIdentityUser
|
||||
/// </summary>
|
||||
protected virtual void InitializeFields()
|
||||
{
|
||||
CreatedOn = DateTime.UtcNow;
|
||||
Claims = new List<MongoClaim>();
|
||||
Logins = new List<UserLoginInfo>();
|
||||
Roles = new List<TKey>();
|
||||
Tokens = new List<Token>();
|
||||
Id = IdGenerator.GetId<TKey>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -166,7 +179,6 @@ namespace AspNetCore.Identity.MongoDbCore.Models
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Add a role to the user.
|
||||
/// </summary>
|
||||
@@ -266,7 +278,6 @@ namespace AspNetCore.Identity.MongoDbCore.Models
|
||||
|
||||
#region Token Management
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Sets the token to a new value.
|
||||
/// </summary>
|
||||
@@ -360,36 +371,5 @@ namespace AspNetCore.Identity.MongoDbCore.Models
|
||||
|
||||
#endregion Token Management
|
||||
|
||||
private void InitializeFields()
|
||||
{
|
||||
CreatedOn = DateTime.UtcNow;
|
||||
Claims = new List<MongoClaim>();
|
||||
Logins = new List<UserLoginInfo>();
|
||||
Roles = new List<TKey>();
|
||||
Tokens = new List<Token>();
|
||||
Guid guidValue = Guid.NewGuid();
|
||||
|
||||
var idTypeName = typeof(TKey).Name;
|
||||
switch (idTypeName)
|
||||
{
|
||||
case "Guid":
|
||||
Id = (TKey)(object)guidValue;
|
||||
break;
|
||||
case "Int16":
|
||||
Id = (TKey)(object)GlobalVariables.Random.Next(1, short.MaxValue);
|
||||
break;
|
||||
case "Int32":
|
||||
Id = (TKey)(object)GlobalVariables.Random.Next(1, int.MaxValue);
|
||||
break;
|
||||
case "Int64":
|
||||
Id = (TKey)(object)(GlobalVariables.Random.NextLong(1, long.MaxValue));
|
||||
break;
|
||||
case "String":
|
||||
Id = (TKey)(object)guidValue.ToString();
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+14
-13
@@ -123,6 +123,16 @@ namespace AspNetCore.Identity.MongoDbCore
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A navigation property for the roles the store contains.
|
||||
/// </summary>
|
||||
public virtual IQueryable<TRole> Roles => RolesCollection.AsQueryable();
|
||||
|
||||
/// <summary>
|
||||
/// A navigation property for the roles the store contains.
|
||||
/// </summary>
|
||||
public virtual IMongoCollection<TRole> RolesCollection => Context.GetCollection<TRole, TKey>();
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the <see cref="IdentityErrorDescriber"/> for any error that occurred with the current operation.
|
||||
/// </summary>
|
||||
@@ -170,8 +180,7 @@ namespace AspNetCore.Identity.MongoDbCore
|
||||
}
|
||||
var oldStamp = role.ConcurrencyStamp;
|
||||
role.ConcurrencyStamp = Guid.NewGuid().ToString();
|
||||
var collection = MongoRepository.Context.GetCollection<TRole>();
|
||||
var updateRes = await collection.ReplaceOneAsync(x => x.Id.Equals(role.Id)
|
||||
var updateRes = await RolesCollection.ReplaceOneAsync(x => x.Id.Equals(role.Id)
|
||||
&& x.ConcurrencyStamp.Equals(oldStamp),
|
||||
role);
|
||||
if (updateRes.ModifiedCount == 0)
|
||||
@@ -197,8 +206,7 @@ namespace AspNetCore.Identity.MongoDbCore
|
||||
}
|
||||
var oldStamp = role.ConcurrencyStamp;
|
||||
role.ConcurrencyStamp = Guid.NewGuid().ToString();
|
||||
var collection = MongoRepository.Context.GetCollection<TRole>();
|
||||
var deleteRes = await collection.DeleteOneAsync(x => x.Id.Equals(role.Id)
|
||||
var deleteRes = await RolesCollection.DeleteOneAsync(x => x.Id.Equals(role.Id)
|
||||
&& x.ConcurrencyStamp.Equals(oldStamp));
|
||||
if (deleteRes.DeletedCount == 0)
|
||||
{
|
||||
@@ -272,11 +280,7 @@ namespace AspNetCore.Identity.MongoDbCore
|
||||
/// <returns>An instance of <typeparamref name="TKey"/> representing the provided <paramref name="id"/>.</returns>
|
||||
public virtual TKey ConvertIdFromString(string id)
|
||||
{
|
||||
if (id == null)
|
||||
{
|
||||
return default(TKey);
|
||||
}
|
||||
return (TKey)TypeDescriptor.GetConverter(typeof(TKey)).ConvertFromInvariantString(id);
|
||||
return id.ToTKey<TKey>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -448,10 +452,7 @@ namespace AspNetCore.Identity.MongoDbCore
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A navigation property for the roles the store contains.
|
||||
/// </summary>
|
||||
public virtual IQueryable<TRole> Roles => Context.GetCollection<TRole>().AsQueryable();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Creates a entity representing a role claim.
|
||||
|
||||
@@ -118,7 +118,7 @@ namespace AspNetCore.Identity.MongoDbCore
|
||||
}
|
||||
}
|
||||
|
||||
private IMongoCollection<TUser> UsersSet { get { return Context.GetCollection<TUser>(); } }
|
||||
private IMongoCollection<TUser> UsersCollection { get { return Context.GetCollection<TUser, TKey>(); } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a flag indicating if changes should be persisted after CreateAsync, UpdateAsync and DeleteAsync are called.
|
||||
@@ -150,7 +150,7 @@ namespace AspNetCore.Identity.MongoDbCore
|
||||
{
|
||||
throw new ArgumentNullException(nameof(user));
|
||||
}
|
||||
await UsersSet.InsertOneAsync(user);
|
||||
await UsersCollection.InsertOneAsync(user);
|
||||
await SaveChanges(cancellationToken);
|
||||
return IdentityResult.Success;
|
||||
}
|
||||
@@ -171,8 +171,7 @@ namespace AspNetCore.Identity.MongoDbCore
|
||||
}
|
||||
var oldStamp = user.ConcurrencyStamp;
|
||||
user.ConcurrencyStamp = Guid.NewGuid().ToString();
|
||||
var collection = MongoRepository.Context.GetCollection<TUser>();
|
||||
var updateRes = await collection.ReplaceOneAsync(x => x.Id.Equals(user.Id)
|
||||
var updateRes = await UsersCollection.ReplaceOneAsync(x => x.Id.Equals(user.Id)
|
||||
&& x.ConcurrencyStamp.Equals(oldStamp),
|
||||
user);
|
||||
if(updateRes.ModifiedCount == 0)
|
||||
@@ -202,8 +201,7 @@ namespace AspNetCore.Identity.MongoDbCore
|
||||
user.Tokens.Clear();
|
||||
var oldStamp = user.ConcurrencyStamp;
|
||||
user.ConcurrencyStamp = Guid.NewGuid().ToString();
|
||||
var collection = MongoRepository.Context.GetCollection<TUser>();
|
||||
var deleteRes = await collection.DeleteOneAsync(x => x.Id.Equals(user.Id)
|
||||
var deleteRes = await UsersCollection.DeleteOneAsync(x => x.Id.Equals(user.Id)
|
||||
&& x.ConcurrencyStamp.Equals(oldStamp));
|
||||
if (deleteRes.DeletedCount == 0)
|
||||
{
|
||||
@@ -248,7 +246,7 @@ namespace AspNetCore.Identity.MongoDbCore
|
||||
/// </summary>
|
||||
public override IQueryable<TUser> Users
|
||||
{
|
||||
get { return UsersSet.AsQueryable(); }
|
||||
get { return UsersCollection.AsQueryable(); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -539,8 +537,7 @@ namespace AspNetCore.Identity.MongoDbCore
|
||||
}
|
||||
var filter = Builders<TUser>.Filter.ElemMatch(x => x.Claims, userClaims => userClaims.Value.Equals(claim.Value)
|
||||
&& userClaims.Type.Equals(claim.Type));
|
||||
var collection = MongoRepository.Context.GetCollection<TUser>();
|
||||
var cursor = collection.Find(filter);
|
||||
var cursor = UsersCollection.Find(filter);
|
||||
var res = await cursor.ToListAsync();
|
||||
return res;
|
||||
}
|
||||
|
||||
+53
-35
@@ -14,6 +14,8 @@ using AspNetCore.Identity.MongoDbCore.Extensions;
|
||||
using AspNetCore.Identity.MongoDbCore.Models;
|
||||
using AspNetCore.Identity.MongoDbCore.Infrastructure;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using System.ComponentModel;
|
||||
using MongoDB.Bson;
|
||||
|
||||
namespace AspNetCore.Identity.MongoDbCore
|
||||
{
|
||||
@@ -130,21 +132,29 @@ namespace AspNetCore.Identity.MongoDbCore
|
||||
/// </summary>
|
||||
private static TContext Context { get; set; }
|
||||
|
||||
private static object MongoRepositoryInitializationLock = new object();
|
||||
private static IMongoRepository _mongoRepository;
|
||||
private static IMongoRepository MongoRepository
|
||||
{
|
||||
get
|
||||
{
|
||||
// double checked locking to prevent race to initialize the repository in multithreaded environment.
|
||||
if (_mongoRepository == null)
|
||||
{
|
||||
_mongoRepository = new MongoRepository(Context);
|
||||
lock (MongoRepositoryInitializationLock)
|
||||
{
|
||||
if (_mongoRepository == null)
|
||||
{
|
||||
_mongoRepository = new MongoRepository(Context);
|
||||
}
|
||||
}
|
||||
}
|
||||
return _mongoRepository;
|
||||
}
|
||||
}
|
||||
|
||||
private IMongoCollection<TUser> UsersSet { get { return Context.GetCollection<TUser>(); } }
|
||||
private IMongoCollection<TRole> Roles { get { return Context.GetCollection<TRole>(); } }
|
||||
private IMongoCollection<TUser> UsersCollection { get { return Context.GetCollection<TUser, TKey>(); } }
|
||||
private IMongoCollection<TRole> RolesCollection { get { return Context.GetCollection<TRole, TKey>(); } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a flag indicating if changes should be persisted after CreateAsync, UpdateAsync and DeleteAsync are called.
|
||||
@@ -176,7 +186,7 @@ namespace AspNetCore.Identity.MongoDbCore
|
||||
{
|
||||
throw new ArgumentNullException(nameof(user));
|
||||
}
|
||||
await UsersSet.InsertOneAsync(user);
|
||||
await UsersCollection.InsertOneAsync(user);
|
||||
await SaveChanges(cancellationToken);
|
||||
return IdentityResult.Success;
|
||||
}
|
||||
@@ -197,11 +207,11 @@ namespace AspNetCore.Identity.MongoDbCore
|
||||
}
|
||||
var oldStamp = user.ConcurrencyStamp;
|
||||
user.ConcurrencyStamp = Guid.NewGuid().ToString();
|
||||
var collection = MongoRepository.Context.GetCollection<TUser>();
|
||||
var updateRes = await collection.ReplaceOneAsync(x => x.Id.Equals(user.Id)
|
||||
&& x.ConcurrencyStamp.Equals(oldStamp),
|
||||
var collection = MongoRepository.Context.GetCollection<TUser, TKey>();
|
||||
var updateRes = await collection.ReplaceOneAsync(x => x.Id.Equals(user.Id)
|
||||
&& x.ConcurrencyStamp.Equals(oldStamp),
|
||||
user);
|
||||
if(updateRes.ModifiedCount == 0)
|
||||
if (updateRes.ModifiedCount == 0)
|
||||
{
|
||||
return IdentityResult.Failed(ErrorDescriber.ConcurrencyFailure());
|
||||
}
|
||||
@@ -228,8 +238,7 @@ namespace AspNetCore.Identity.MongoDbCore
|
||||
user.Tokens.Clear();
|
||||
var oldStamp = user.ConcurrencyStamp;
|
||||
user.ConcurrencyStamp = Guid.NewGuid().ToString();
|
||||
var collection = MongoRepository.Context.GetCollection<TUser>();
|
||||
var deleteRes = await collection.DeleteOneAsync(x => x.Id.Equals(user.Id)
|
||||
var deleteRes = await UsersCollection.DeleteOneAsync(x => x.Id.Equals(user.Id)
|
||||
&& x.ConcurrencyStamp.Equals(oldStamp));
|
||||
if (deleteRes.DeletedCount == 0)
|
||||
{
|
||||
@@ -254,6 +263,16 @@ namespace AspNetCore.Identity.MongoDbCore
|
||||
return MongoRepository.GetByIdAsync<TUser, TKey>(id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts the provided <paramref name="id"/> to a strongly typed key object.
|
||||
/// </summary>
|
||||
/// <param name="id">The id to convert.</param>
|
||||
/// <returns>An instance of <typeparamref name="TKey"/> representing the provided <paramref name="id"/>.</returns>
|
||||
public override TKey ConvertIdFromString(string id)
|
||||
{
|
||||
return id.ToTKey<TKey>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finds and returns a user, if any, who has the specified normalized user name.
|
||||
/// </summary>
|
||||
@@ -274,7 +293,7 @@ namespace AspNetCore.Identity.MongoDbCore
|
||||
/// </summary>
|
||||
public override IQueryable<TUser> Users
|
||||
{
|
||||
get { return UsersSet.AsQueryable(); }
|
||||
get { return UsersCollection.AsQueryable(); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -470,12 +489,12 @@ namespace AspNetCore.Identity.MongoDbCore
|
||||
}
|
||||
|
||||
#pragma warning disable CS1998 // Cette méthode async n'a pas d'opérateur 'await' et elle s'exécutera de façon synchrone
|
||||
/// <summary>
|
||||
/// Get the claims associated with the specified <paramref name="user"/> as an asynchronous operation.
|
||||
/// </summary>
|
||||
/// <param name="user">The user whose claims should be retrieved.</param>
|
||||
/// <param name="cancellationToken">The <see cref="CancellationToken"/> used to propagate notifications that the operation should be canceled.</param>
|
||||
/// <returns>A <see cref="Task{TResult}"/> that contains the claims granted to a user.</returns>
|
||||
/// <summary>
|
||||
/// Get the claims associated with the specified <paramref name="user"/> as an asynchronous operation.
|
||||
/// </summary>
|
||||
/// <param name="user">The user whose claims should be retrieved.</param>
|
||||
/// <param name="cancellationToken">The <see cref="CancellationToken"/> used to propagate notifications that the operation should be canceled.</param>
|
||||
/// <returns>A <see cref="Task{TResult}"/> that contains the claims granted to a user.</returns>
|
||||
public async override Task<IList<Claim>> GetClaimsAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken))
|
||||
#pragma warning restore CS1998 // Cette méthode async n'a pas d'opérateur 'await' et elle s'exécutera de façon synchrone
|
||||
{
|
||||
@@ -610,14 +629,14 @@ namespace AspNetCore.Identity.MongoDbCore
|
||||
}
|
||||
|
||||
#pragma warning disable CS1998 // Cette méthode async n'a pas d'opérateur 'await' et elle s'exécutera de façon synchrone
|
||||
/// <summary>
|
||||
/// Removes the <paramref name="loginProvider"/> given from the specified <paramref name="user"/>.
|
||||
/// </summary>
|
||||
/// <param name="user">The user to remove the login from.</param>
|
||||
/// <param name="loginProvider">The login to remove from the user.</param>
|
||||
/// <param name="providerKey">The key provided by the <paramref name="loginProvider"/> to identify a user.</param>
|
||||
/// <param name="cancellationToken">The <see cref="CancellationToken"/> used to propagate notifications that the operation should be canceled.</param>
|
||||
/// <returns>The <see cref="Task"/> that represents the asynchronous operation.</returns>
|
||||
/// <summary>
|
||||
/// Removes the <paramref name="loginProvider"/> given from the specified <paramref name="user"/>.
|
||||
/// </summary>
|
||||
/// <param name="user">The user to remove the login from.</param>
|
||||
/// <param name="loginProvider">The login to remove from the user.</param>
|
||||
/// <param name="providerKey">The key provided by the <paramref name="loginProvider"/> to identify a user.</param>
|
||||
/// <param name="cancellationToken">The <see cref="CancellationToken"/> used to propagate notifications that the operation should be canceled.</param>
|
||||
/// <returns>The <see cref="Task"/> that represents the asynchronous operation.</returns>
|
||||
public override async Task RemoveLoginAsync(TUser user, string loginProvider, string providerKey,
|
||||
#pragma warning restore CS1998 // Cette méthode async n'a pas d'opérateur 'await' et elle s'exécutera de façon synchrone
|
||||
CancellationToken cancellationToken = default(CancellationToken))
|
||||
@@ -636,14 +655,14 @@ namespace AspNetCore.Identity.MongoDbCore
|
||||
}
|
||||
|
||||
#pragma warning disable CS1998 // Cette méthode async n'a pas d'opérateur 'await' et elle s'exécutera de façon synchrone
|
||||
/// <summary>
|
||||
/// Retrieves the associated logins for the specified <param ref="user"/>.
|
||||
/// </summary>
|
||||
/// <param name="user">The user whose associated logins to retrieve.</param>
|
||||
/// <param name="cancellationToken">The <see cref="CancellationToken"/> used to propagate notifications that the operation should be canceled.</param>
|
||||
/// <returns>
|
||||
/// The <see cref="Task"/> for the asynchronous operation, containing a list of <see cref="UserLoginInfo"/> for the specified <paramref name="user"/>, if any.
|
||||
/// </returns>
|
||||
/// <summary>
|
||||
/// Retrieves the associated logins for the specified <param ref="user"/>.
|
||||
/// </summary>
|
||||
/// <param name="user">The user whose associated logins to retrieve.</param>
|
||||
/// <param name="cancellationToken">The <see cref="CancellationToken"/> used to propagate notifications that the operation should be canceled.</param>
|
||||
/// <returns>
|
||||
/// The <see cref="Task"/> for the asynchronous operation, containing a list of <see cref="UserLoginInfo"/> for the specified <paramref name="user"/>, if any.
|
||||
/// </returns>
|
||||
public async override Task<IList<UserLoginInfo>> GetLoginsAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken))
|
||||
#pragma warning restore CS1998 // Cette méthode async n'a pas d'opérateur 'await' et elle s'exécutera de façon synchrone
|
||||
{
|
||||
@@ -711,8 +730,7 @@ namespace AspNetCore.Identity.MongoDbCore
|
||||
}
|
||||
var filter = Builders<TUser>.Filter.ElemMatch(x => x.Claims, userClaims => userClaims.Value.Equals(claim.Value)
|
||||
&& userClaims.Type.Equals(claim.Type));
|
||||
var collection = MongoRepository.Context.GetCollection<TUser>();
|
||||
var cursor = collection.Find(filter);
|
||||
var cursor = UsersCollection.Find(filter);
|
||||
var res = await cursor.ToListAsync();
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"runtimeTarget": {
|
||||
"name": ".NETCoreApp,Version=v2.0",
|
||||
"signature": "38e5f0ca5f25fc12f74d4c5d8051381123909848"
|
||||
"signature": "38b2f87cafd1a2fa8c7bd3268841c3cd7abe472b"
|
||||
},
|
||||
"compilationOptions": {},
|
||||
"targets": {
|
||||
@@ -11,7 +11,7 @@
|
||||
"Microsoft.AspNetCore.Identity": "2.0.1",
|
||||
"Microsoft.Extensions.Identity.Stores": "2.0.1",
|
||||
"MongoDB.Driver": "2.5.0",
|
||||
"MongoDbGenericRepository": "1.3.4"
|
||||
"MongoDbGenericRepository": "1.3.6"
|
||||
},
|
||||
"runtime": {
|
||||
"AspNetCore.Identity.MongoDbCore.dll": {}
|
||||
@@ -359,7 +359,7 @@
|
||||
"lib/netstandard1.5/MongoDB.Driver.Core.dll": {}
|
||||
}
|
||||
},
|
||||
"MongoDbGenericRepository/1.3.4": {
|
||||
"MongoDbGenericRepository/1.3.6": {
|
||||
"dependencies": {
|
||||
"MongoDB.Driver": "2.5.0"
|
||||
},
|
||||
@@ -1462,12 +1462,12 @@
|
||||
"path": "mongodb.driver.core/2.5.0",
|
||||
"hashPath": "mongodb.driver.core.2.5.0.nupkg.sha512"
|
||||
},
|
||||
"MongoDbGenericRepository/1.3.4": {
|
||||
"MongoDbGenericRepository/1.3.6": {
|
||||
"type": "package",
|
||||
"serviceable": true,
|
||||
"sha512": "sha512-nVtq9UGq6e8I61D1Fc1HIvh4qVA92IkfpcmrNXgG2141qBOpY7U0FbKlz+NOqiJoopY/ejhTBE3QbicsxsoOeg==",
|
||||
"path": "mongodbgenericrepository/1.3.4",
|
||||
"hashPath": "mongodbgenericrepository.1.3.4.nupkg.sha512"
|
||||
"sha512": "sha512-bm4Q5RDLqt6rRZJTDiWvQpHOJ3ACxfELqg0kiZO8dyb7xMEqPQC7urpuLKMpDUmnE/pMBuXe6Pmy9TyTksDbdg==",
|
||||
"path": "mongodbgenericrepository/1.3.6",
|
||||
"hashPath": "mongodbgenericrepository.1.3.6.nupkg.sha512"
|
||||
},
|
||||
"runtime.native.System/4.3.0": {
|
||||
"type": "package",
|
||||
|
||||
Binary file not shown.
@@ -130,6 +130,19 @@
|
||||
<param name="mongoDbIdentityConfiguration">A configuration object of the AspNetCore.Identity.MongoDbCore package.</param>
|
||||
<param name="mongoDbContext">An object representing a MongoDb connection.</param>
|
||||
</member>
|
||||
<member name="T:AspNetCore.Identity.MongoDbCore.Extensions.StringExtensions">
|
||||
<summary>
|
||||
A set of extensions for string.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:AspNetCore.Identity.MongoDbCore.Extensions.StringExtensions.ToTKey``1(System.String)">
|
||||
<summary>
|
||||
Converts the provided <paramref name="id"/> to a strongly typed key object.
|
||||
</summary>
|
||||
<typeparam name="TKey"></typeparam>
|
||||
<param name="id"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="T:AspNetCore.Identity.MongoDbCore.GlobalVariables">
|
||||
<summary>
|
||||
A class holding global variables.
|
||||
@@ -308,6 +321,11 @@
|
||||
</summary>
|
||||
<param name="roleName">The name of the role.</param>
|
||||
</member>
|
||||
<member name="M:AspNetCore.Identity.MongoDbCore.Models.MongoIdentityRole`1.InitializeFields">
|
||||
<summary>
|
||||
Initialize the field of the MongoIdentityRole
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:AspNetCore.Identity.MongoDbCore.Models.MongoIdentityRole`1.#ctor(System.String,`0)">
|
||||
<summary>
|
||||
The constructor for a <see cref="T:AspNetCore.Identity.MongoDbCore.Models.MongoIdentityRole`1"/>, taking a role name and a primary key value.
|
||||
@@ -425,6 +443,11 @@
|
||||
</summary>
|
||||
<param name="userName">The name of the user.</param>
|
||||
</member>
|
||||
<member name="M:AspNetCore.Identity.MongoDbCore.Models.MongoIdentityUser`1.InitializeFields">
|
||||
<summary>
|
||||
Initialize the field of the MongoIdentityUser
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:AspNetCore.Identity.MongoDbCore.Models.MongoIdentityUser`1.SetVersion(System.Int32)">
|
||||
<summary>
|
||||
Sets the version of the schema for the <see cref="T:AspNetCore.Identity.MongoDbCore.Models.MongoIdentityUser`1"/> document.
|
||||
@@ -597,6 +620,16 @@
|
||||
Gets the database context for this store.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:AspNetCore.Identity.MongoDbCore.MongoRoleStore`5.Roles">
|
||||
<summary>
|
||||
A navigation property for the roles the store contains.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:AspNetCore.Identity.MongoDbCore.MongoRoleStore`5.RolesCollection">
|
||||
<summary>
|
||||
A navigation property for the roles the store contains.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:AspNetCore.Identity.MongoDbCore.MongoRoleStore`5.ErrorDescriber">
|
||||
<summary>
|
||||
Gets or sets the <see cref="T:Microsoft.AspNetCore.Identity.IdentityErrorDescriber"/> for any error that occurred with the current operation.
|
||||
@@ -742,11 +775,6 @@
|
||||
<param name="cancellationToken">The <see cref="T:System.Threading.CancellationToken"/> used to propagate notifications that the operation should be canceled.</param>
|
||||
<returns>The <see cref="T:System.Threading.Tasks.Task"/> that represents the asynchronous operation.</returns>
|
||||
</member>
|
||||
<member name="P:AspNetCore.Identity.MongoDbCore.MongoRoleStore`5.Roles">
|
||||
<summary>
|
||||
A navigation property for the roles the store contains.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:AspNetCore.Identity.MongoDbCore.MongoRoleStore`5.CreateRoleClaim(`0,System.Security.Claims.Claim)">
|
||||
<summary>
|
||||
Creates a entity representing a role claim.
|
||||
@@ -1360,6 +1388,13 @@
|
||||
The <see cref="T:System.Threading.Tasks.Task"/> that represents the asynchronous operation, containing the user matching the specified <paramref name="userId"/> if it exists.
|
||||
</returns>
|
||||
</member>
|
||||
<member name="M:AspNetCore.Identity.MongoDbCore.MongoUserStore`9.ConvertIdFromString(System.String)">
|
||||
<summary>
|
||||
Converts the provided <paramref name="id"/> to a strongly typed key object.
|
||||
</summary>
|
||||
<param name="id">The id to convert.</param>
|
||||
<returns>An instance of <typeparamref name="TKey"/> representing the provided <paramref name="id"/>.</returns>
|
||||
</member>
|
||||
<member name="M:AspNetCore.Identity.MongoDbCore.MongoUserStore`9.FindByNameAsync(System.String,System.Threading.CancellationToken)">
|
||||
<summary>
|
||||
Finds and returns a user, if any, who has the specified normalized user name.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"runtimeTarget": {
|
||||
"name": ".NETStandard,Version=v2.0/",
|
||||
"signature": "9926fc91f43fdc960144838c1bcb58195d97fdd2"
|
||||
"signature": "777efc9083cc946975cf0e3ebd09810483543683"
|
||||
},
|
||||
"compilationOptions": {},
|
||||
"targets": {
|
||||
@@ -12,7 +12,7 @@
|
||||
"Microsoft.AspNetCore.Identity": "2.0.1",
|
||||
"Microsoft.Extensions.Identity.Stores": "2.0.1",
|
||||
"MongoDB.Driver": "2.5.0",
|
||||
"MongoDbGenericRepository": "1.3.4",
|
||||
"MongoDbGenericRepository": "1.3.6",
|
||||
"NETStandard.Library": "2.0.1"
|
||||
},
|
||||
"runtime": {
|
||||
@@ -360,7 +360,7 @@
|
||||
"lib/netstandard1.5/MongoDB.Driver.Core.dll": {}
|
||||
}
|
||||
},
|
||||
"MongoDbGenericRepository/1.3.4": {
|
||||
"MongoDbGenericRepository/1.3.6": {
|
||||
"dependencies": {
|
||||
"MongoDB.Driver": "2.5.0"
|
||||
},
|
||||
@@ -1427,12 +1427,12 @@
|
||||
"path": "mongodb.driver.core/2.5.0",
|
||||
"hashPath": "mongodb.driver.core.2.5.0.nupkg.sha512"
|
||||
},
|
||||
"MongoDbGenericRepository/1.3.4": {
|
||||
"MongoDbGenericRepository/1.3.6": {
|
||||
"type": "package",
|
||||
"serviceable": true,
|
||||
"sha512": "sha512-nVtq9UGq6e8I61D1Fc1HIvh4qVA92IkfpcmrNXgG2141qBOpY7U0FbKlz+NOqiJoopY/ejhTBE3QbicsxsoOeg==",
|
||||
"path": "mongodbgenericrepository/1.3.4",
|
||||
"hashPath": "mongodbgenericrepository.1.3.4.nupkg.sha512"
|
||||
"sha512": "sha512-bm4Q5RDLqt6rRZJTDiWvQpHOJ3ACxfELqg0kiZO8dyb7xMEqPQC7urpuLKMpDUmnE/pMBuXe6Pmy9TyTksDbdg==",
|
||||
"path": "mongodbgenericrepository/1.3.6",
|
||||
"hashPath": "mongodbgenericrepository.1.3.6.nupkg.sha512"
|
||||
},
|
||||
"NETStandard.Library/2.0.1": {
|
||||
"type": "package",
|
||||
|
||||
Binary file not shown.
@@ -130,6 +130,19 @@
|
||||
<param name="mongoDbIdentityConfiguration">A configuration object of the AspNetCore.Identity.MongoDbCore package.</param>
|
||||
<param name="mongoDbContext">An object representing a MongoDb connection.</param>
|
||||
</member>
|
||||
<member name="T:AspNetCore.Identity.MongoDbCore.Extensions.StringExtensions">
|
||||
<summary>
|
||||
A set of extensions for string.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:AspNetCore.Identity.MongoDbCore.Extensions.StringExtensions.ToTKey``1(System.String)">
|
||||
<summary>
|
||||
Converts the provided <paramref name="id"/> to a strongly typed key object.
|
||||
</summary>
|
||||
<typeparam name="TKey"></typeparam>
|
||||
<param name="id"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="T:AspNetCore.Identity.MongoDbCore.GlobalVariables">
|
||||
<summary>
|
||||
A class holding global variables.
|
||||
@@ -308,6 +321,11 @@
|
||||
</summary>
|
||||
<param name="roleName">The name of the role.</param>
|
||||
</member>
|
||||
<member name="M:AspNetCore.Identity.MongoDbCore.Models.MongoIdentityRole`1.InitializeFields">
|
||||
<summary>
|
||||
Initialize the field of the MongoIdentityRole
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:AspNetCore.Identity.MongoDbCore.Models.MongoIdentityRole`1.#ctor(System.String,`0)">
|
||||
<summary>
|
||||
The constructor for a <see cref="T:AspNetCore.Identity.MongoDbCore.Models.MongoIdentityRole`1"/>, taking a role name and a primary key value.
|
||||
@@ -425,6 +443,11 @@
|
||||
</summary>
|
||||
<param name="userName">The name of the user.</param>
|
||||
</member>
|
||||
<member name="M:AspNetCore.Identity.MongoDbCore.Models.MongoIdentityUser`1.InitializeFields">
|
||||
<summary>
|
||||
Initialize the field of the MongoIdentityUser
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:AspNetCore.Identity.MongoDbCore.Models.MongoIdentityUser`1.SetVersion(System.Int32)">
|
||||
<summary>
|
||||
Sets the version of the schema for the <see cref="T:AspNetCore.Identity.MongoDbCore.Models.MongoIdentityUser`1"/> document.
|
||||
@@ -597,6 +620,16 @@
|
||||
Gets the database context for this store.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:AspNetCore.Identity.MongoDbCore.MongoRoleStore`5.Roles">
|
||||
<summary>
|
||||
A navigation property for the roles the store contains.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:AspNetCore.Identity.MongoDbCore.MongoRoleStore`5.RolesCollection">
|
||||
<summary>
|
||||
A navigation property for the roles the store contains.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:AspNetCore.Identity.MongoDbCore.MongoRoleStore`5.ErrorDescriber">
|
||||
<summary>
|
||||
Gets or sets the <see cref="T:Microsoft.AspNetCore.Identity.IdentityErrorDescriber"/> for any error that occurred with the current operation.
|
||||
@@ -742,11 +775,6 @@
|
||||
<param name="cancellationToken">The <see cref="T:System.Threading.CancellationToken"/> used to propagate notifications that the operation should be canceled.</param>
|
||||
<returns>The <see cref="T:System.Threading.Tasks.Task"/> that represents the asynchronous operation.</returns>
|
||||
</member>
|
||||
<member name="P:AspNetCore.Identity.MongoDbCore.MongoRoleStore`5.Roles">
|
||||
<summary>
|
||||
A navigation property for the roles the store contains.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:AspNetCore.Identity.MongoDbCore.MongoRoleStore`5.CreateRoleClaim(`0,System.Security.Claims.Claim)">
|
||||
<summary>
|
||||
Creates a entity representing a role claim.
|
||||
@@ -1360,6 +1388,13 @@
|
||||
The <see cref="T:System.Threading.Tasks.Task"/> that represents the asynchronous operation, containing the user matching the specified <paramref name="userId"/> if it exists.
|
||||
</returns>
|
||||
</member>
|
||||
<member name="M:AspNetCore.Identity.MongoDbCore.MongoUserStore`9.ConvertIdFromString(System.String)">
|
||||
<summary>
|
||||
Converts the provided <paramref name="id"/> to a strongly typed key object.
|
||||
</summary>
|
||||
<param name="id">The id to convert.</param>
|
||||
<returns>An instance of <typeparamref name="TKey"/> representing the provided <paramref name="id"/>.</returns>
|
||||
</member>
|
||||
<member name="M:AspNetCore.Identity.MongoDbCore.MongoUserStore`9.FindByNameAsync(System.String,System.Threading.CancellationToken)">
|
||||
<summary>
|
||||
Finds and returns a user, if any, who has the specified normalized user name.
|
||||
|
||||
+2
-2
@@ -7,7 +7,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AspNetCore.Identity.MongoDbCore" Version="1.0.7" />
|
||||
<PackageReference Include="AspNetCore.Identity.MongoDbCore" Version="1.0.8" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication" Version="2.0.1" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Hosting" Version="2.0.1" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Http" />
|
||||
@@ -21,7 +21,7 @@
|
||||
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="2.0.1" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
|
||||
<PackageReference Include="MongoDB.Driver" Version="2.5.0" />
|
||||
<PackageReference Include="MongoDbGenericRepository" Version="1.3.4" />
|
||||
<PackageReference Include="MongoDbGenericRepository" Version="1.3.6" />
|
||||
<PackageReference Include="Moq" Version="4.8.1" />
|
||||
<PackageReference Include="xunit" Version="2.3.1" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
|
||||
|
||||
+1
-1
@@ -162,7 +162,7 @@ namespace AspNetCore.Identity.MongoDbCore.Test
|
||||
|
||||
private IQueryable<TUser> GetQueryable()
|
||||
{
|
||||
return Container.MongoRepository.Context.GetCollection<TUser>().AsQueryable();
|
||||
return Container.MongoRepository.Context.GetCollection<TUser, TKey>().AsQueryable();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
+1
-1
@@ -87,7 +87,7 @@ namespace AspNetCore.Identity.MongoDbCore.Test
|
||||
|
||||
private IQueryable<TUser> GetQueryable()
|
||||
{
|
||||
return Container.MongoRepository.Context.GetCollection<TUser>().AsQueryable();
|
||||
return Container.MongoRepository.Context.GetCollection<TUser, TKey>().AsQueryable();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using AspNetCore.Identity.MongoDbCore.Models;
|
||||
using MongoDbGenericRepository;
|
||||
using AspNetCore.Identity.MongoDbCore.IntegrationTests.Infrastructure;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using MongoDB.Bson;
|
||||
|
||||
namespace AspNetCore.Identity.MongoDbCore.Test
|
||||
{
|
||||
public class ObjectIdUser : MongoIdentityUser<ObjectId>
|
||||
{
|
||||
public ObjectIdUser() : base()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class ObjectIdRole : MongoIdentityRole<ObjectId>
|
||||
{
|
||||
public ObjectIdRole() : base()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class UserStoreObjectIdTest : MongoDbStoreTestBase<ObjectIdUser, ObjectIdRole, ObjectId>
|
||||
{
|
||||
public UserStoreObjectIdTest(MongoDatabaseFixture<ObjectIdUser, ObjectIdRole, ObjectId> fixture)
|
||||
: base(fixture)
|
||||
{
|
||||
}
|
||||
|
||||
public class ApplicationUserStore : MongoUserStore<ObjectIdUser, ObjectIdRole, IMongoDbContext, ObjectId>
|
||||
{
|
||||
public ApplicationUserStore(IMongoDbContext context) : base(Container.MongoRepository.Context) { }
|
||||
}
|
||||
|
||||
public class ApplicationRoleStore : MongoRoleStore<ObjectIdRole, IMongoDbContext, ObjectId>
|
||||
{
|
||||
public ApplicationRoleStore(IMongoDbContext context) : base(Container.MongoRepository.Context) { }
|
||||
}
|
||||
|
||||
protected override void AddUserStore(IServiceCollection services, object context = null)
|
||||
{
|
||||
services.AddSingleton<IUserStore<ObjectIdUser>>(new ApplicationUserStore(Container.MongoRepository.Context));
|
||||
}
|
||||
|
||||
protected override void AddRoleStore(IServiceCollection services, object context = null)
|
||||
{
|
||||
services.AddSingleton<IRoleStore<ObjectIdRole>>(new ApplicationRoleStore(Container.MongoRepository.Context));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -31,7 +31,7 @@ namespace AspNetCore.Identity.MongoDbCore.Test
|
||||
var userIds = UsersToDelete.ToList().Select(e => e.Id);
|
||||
if (userIds.Any())
|
||||
{
|
||||
Context.GetCollection<TUser>().DeleteMany(e => userIds.Contains(e.Id));
|
||||
Context.GetCollection<TUser, TKey>().DeleteMany(e => userIds.Contains(e.Id));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -57,12 +57,12 @@ namespace AspNetCore.Identity.MongoDbCore.Test
|
||||
var userIds = UsersToDelete.ToList().Select(e => e.Id);
|
||||
if (userIds.Any())
|
||||
{
|
||||
Context.GetCollection<TUser>().DeleteMany(e => userIds.Contains(e.Id));
|
||||
Context.GetCollection<TUser, TKey>().DeleteMany(e => userIds.Contains(e.Id));
|
||||
}
|
||||
var roleIds = RolesToDelete.ToList().Select(e => e.Id);
|
||||
if (roleIds.Any())
|
||||
{
|
||||
Context.GetCollection<TRole>().DeleteMany(e => roleIds.Contains(e.Id));
|
||||
Context.GetCollection<TRole, TKey>().DeleteMany(e => roleIds.Contains(e.Id));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user