diff --git a/MongoDB.AspNet.Identity.csproj b/MongoDB.AspNet.Identity.csproj
index ba38609..b791550 100644
--- a/MongoDB.AspNet.Identity.csproj
+++ b/MongoDB.AspNet.Identity.csproj
@@ -41,16 +41,20 @@
bin\MongoDB.AspNet.Identity.XML
-
- packages\Microsoft.AspNet.Identity.Core.1.0.0\lib\net45\Microsoft.AspNet.Identity.Core.dll
+
+ False
+ packages\Microsoft.AspNet.Identity.Core.2.2.0\lib\net45\Microsoft.AspNet.Identity.Core.dll
-
+
False
- packages\mongocsharpdriver.1.8.3\lib\net35\MongoDB.Bson.dll
+ packages\MongoDB.Bson.2.0.0\lib\net45\MongoDB.Bson.dll
-
+
False
- packages\mongocsharpdriver.1.8.3\lib\net35\MongoDB.Driver.dll
+ packages\MongoDB.Driver.2.0.0\lib\net45\MongoDB.Driver.dll
+
+
+ packages\MongoDB.Driver.Core.2.0.0\lib\net45\MongoDB.Driver.Core.dll
diff --git a/UserStore.cs b/UserStore.cs
index 93613eb..f992278 100644
--- a/UserStore.cs
+++ b/UserStore.cs
@@ -7,7 +7,6 @@
using Microsoft.AspNet.Identity;
using MongoDB.Bson;
using MongoDB.Driver;
-using MongoDB.Driver.Builders;
namespace MongoDB.AspNet.Identity
{
@@ -15,7 +14,7 @@ namespace MongoDB.AspNet.Identity
/// Class UserStore.
///
/// The type of the t user.
- public class UserStore : IUserLoginStore, IUserClaimStore, IUserRoleStore,
+ public class UserStore : IUserStore, IUserLoginStore, IUserClaimStore, IUserRoleStore,
IUserPasswordStore, IUserSecurityStampStore
where TUser : IdentityUser
{
@@ -24,7 +23,7 @@ public class UserStore : IUserLoginStore, IUserClaimStore,
///
/// The database
///
- private readonly MongoDatabase db;
+ private readonly IMongoDatabase db;
///
/// The _disposed
@@ -42,16 +41,15 @@ public class UserStore : IUserLoginStore, IUserClaimStore,
/// The connection string.
/// MongoDatabase.
/// No database name specified in connection string
- private MongoDatabase GetDatabaseFromSqlStyle(string connectionString)
+ private IMongoDatabase GetDatabaseFromSqlStyle(string connectionString)
{
- var conString = new MongoConnectionStringBuilder(connectionString);
- MongoClientSettings settings = MongoClientSettings.FromConnectionStringBuilder(conString);
- MongoServer server = new MongoClient(settings).GetServer();
- if (conString.DatabaseName == null)
+ MongoUrl url = MongoUrl.Create(connectionString);
+ if (url.DatabaseName == null)
{
throw new Exception("No database name specified in connection string");
}
- return server.GetDatabase(conString.DatabaseName);
+ MongoClientSettings settings = MongoClientSettings.FromUrl(url);
+ return new MongoClient(settings).GetDatabase(url.DatabaseName);
}
///
@@ -59,15 +57,13 @@ private MongoDatabase GetDatabaseFromSqlStyle(string connectionString)
///
/// The URL.
/// MongoDatabase.
- private MongoDatabase GetDatabaseFromUrl(MongoUrl url)
+ private IMongoDatabase GetDatabaseFromUrl(MongoUrl url)
{
- var client = new MongoClient(url);
- MongoServer server = client.GetServer();
if (url.DatabaseName == null)
{
throw new Exception("No database name specified in connection string");
}
- return server.GetDatabase(url.DatabaseName); // WriteConcern defaulted to Acknowledged
+ return new MongoClient(url).GetDatabase(url.DatabaseName); // WriteConcern defaulted to Acknowledged
}
///
@@ -76,22 +72,22 @@ private MongoDatabase GetDatabaseFromUrl(MongoUrl url)
/// The connection string.
/// Name of the database.
/// MongoDatabase.
- private MongoDatabase GetDatabase(string connectionString, string dbName)
+ private IMongoDatabase GetDatabase(string connectionString, string dbName)
{
var client = new MongoClient(connectionString);
- MongoServer server = client.GetServer();
- return server.GetDatabase(dbName);
+ return client.GetDatabase(dbName);
}
#endregion
#region Constructors
-
+
///
/// Initializes a new instance of the class. Uses DefaultConnection name if none was
/// specified.
///
- public UserStore() : this("DefaultConnection")
+ public UserStore()
+ : this("DefaultConnection")
{
}
@@ -144,13 +140,13 @@ public UserStore(string connectionNameOrUrl, string dbName)
/// Initializes a new instance of the class using a already initialized Mongo Database.
///
/// The mongo database.
- public UserStore(MongoDatabase mongoDatabase)
+ public UserStore(IMongoDatabase mongoDatabase)
{
db = mongoDatabase;
}
- ///
+ ///
/// Initializes a new instance of the class.
///
/// Name of the connection from ConfigurationManager.ConnectionStrings[].
@@ -246,7 +242,7 @@ public Task CreateAsync(TUser user)
if (user == null)
throw new ArgumentNullException("user");
- db.GetCollection(collectionName).Insert(user);
+ db.GetCollection(collectionName).InsertOneAsync(user);
return Task.FromResult(user);
}
@@ -263,7 +259,7 @@ public Task DeleteAsync(TUser user)
if (user == null)
throw new ArgumentNullException("user");
- db.GetCollection(collectionName).Remove((Query.EQ("_id", ObjectId.Parse(user.Id))));
+ db.GetCollection(collectionName).DeleteOneAsync(x => x.Id == user.Id);
return Task.FromResult(true);
}
@@ -275,8 +271,8 @@ public Task DeleteAsync(TUser user)
public Task FindByIdAsync(string userId)
{
ThrowIfDisposed();
- TUser user = db.GetCollection(collectionName).FindOne((Query.EQ("_id", ObjectId.Parse(userId))));
- return Task.FromResult(user);
+
+ return db.GetCollection(collectionName).Find(u => u.Id == userId).FirstOrDefaultAsync();
}
///
@@ -287,9 +283,9 @@ public Task FindByIdAsync(string userId)
public Task FindByNameAsync(string userName)
{
ThrowIfDisposed();
-
- TUser user = db.GetCollection(collectionName).FindOne((Query.EQ("UserName", userName)));
- return Task.FromResult(user);
+
+ return
+ db.GetCollection(collectionName).Find(u => u.UserName == userName).FirstOrDefaultAsync();
}
///
@@ -305,7 +301,7 @@ public Task UpdateAsync(TUser user)
throw new ArgumentNullException("user");
db.GetCollection(collectionName)
- .Update(Query.EQ("_id", ObjectId.Parse(user.Id)), Update.Replace(user), UpdateFlags.Upsert);
+ .ReplaceOneAsync(x => x.Id == user.Id, user);
return Task.FromResult(user);
}
@@ -346,13 +342,9 @@ public Task AddLoginAsync(TUser user, UserLoginInfo login)
/// Task{`0}.
public Task FindAsync(UserLoginInfo login)
{
- TUser user = null;
- user =
- db.GetCollection(collectionName)
- .FindOne(Query.And(Query.EQ("Logins.LoginProvider", login.LoginProvider),
- Query.EQ("Logins.ProviderKey", login.ProviderKey)));
-
- return Task.FromResult(user);
+ return
+ db.GetCollection(collectionName)
+ .Find(u => u.Logins.Any(l => l.LoginProvider == login.LoginProvider && l.ProviderKey == login.ProviderKey) == true).FirstOrDefaultAsync();
}
///
@@ -546,4 +538,3 @@ private void ThrowIfDisposed()
#endregion
}
}
-
\ No newline at end of file
diff --git a/packages.config b/packages.config
index 0e77e46..46d9cc3 100644
--- a/packages.config
+++ b/packages.config
@@ -1,5 +1,7 @@
-
-
+
+
+
+
\ No newline at end of file