コード例 #1
0
        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));
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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));
        }