public async Task <TUser> FindByNameAsync(string userName) { var userByName = await session.LoadAsync <IdentityUserByUserName>(Util.GetIdentityUserByUserNameId(userName)); if (userByName == null) { return(null); } return(await FindByIdAsync(userByName.UserId)); }
public async Task DeleteAsync(TUser user) { ThrowIfDisposed(); if (user == null) { throw new ArgumentNullException(nameof(user)); } var userByName = await session.LoadAsync <IdentityUserByUserName>(Util.GetIdentityUserByUserNameId(user.UserName)); if (userByName != null) { session.Delete(userByName); } this.session.Delete(user); }
public async Task CreateAsync(TUser user) { ThrowIfDisposed(); if (user == null) { throw new ArgumentNullException(nameof(user)); } if (string.IsNullOrEmpty(user.Id)) { var conventions = session.Advanced.DocumentStore.Conventions; var entityName = conventions.GetCollectionName(typeof(TUser)); var separator = conventions.IdentityPartsSeparator; var id = $"{entityName}{separator}{user.Email}"; user.Id = id; } await session.StoreAsync(user); // This model allows us to lookup a user by name in order to get the id var userByName = new IdentityUserByUserName(user.Id, user.UserName); await session.StoreAsync(userByName, Util.GetIdentityUserByUserNameId(user.UserName)); }