예제 #1
0
        /// <summary>
        /// Deletes all claims from a user given a userId
        /// </summary>
        /// <param name="userId">The user's id</param>
        /// <returns></returns>
        public int Delete(string userId)
        {
            var userClaim = _database.AspNetUserClaims.Where(c => c.UserId == userId);

            _database.AspNetUserClaims.RemoveRange(userClaim);
            return(_database.SaveChanges());
        }
예제 #2
0
        /// <summary>
        /// Deltes a role from the AspNetRoles table
        /// </summary>
        /// <param name="roleId">The role Id</param>
        /// <returns></returns>
        public int Delete(string roleId)
        {
            var role = _database.AspNetRoles.Find(roleId);

            _database.AspNetRoles.Remove(role);
            return(_database.SaveChanges());
        }
예제 #3
0
        /// <summary>
        /// Sets the user's password hash
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="passwordHash"></param>
        /// <returns></returns>
        public int SetPasswordHash(string userId, string passwordHash)
        {
            var newUser = _database.AspNetUsers.Find(userId);

            newUser.PasswordHash = passwordHash;

            return(_database.SaveChanges());
        }
        /// <summary>
        /// Deletes a login from a user in the AspNetUserLogins table
        /// </summary>
        /// <param name="user">User to have login deleted</param>
        /// <param name="login">Login to be deleted from user</param>
        /// <returns></returns>
        public int Delete(IdentityUser user, UserLoginInfo login)
        {
            var userLogin = _database.AspNetUserLogins
                            .Where(x => x.UserId == user.Id && x.LoginProvider == login.LoginProvider && x.ProviderKey == login.ProviderKey);

            _database.AspNetUserLogins.RemoveRange(userLogin);
            return(_database.SaveChanges());
        }
        /// <summary>
        /// Deletes all roles from a user in the AspNetUserRoles table
        /// </summary>
        /// <param name="userId">The user's id</param>
        /// <returns></returns>
        public int Delete(string userId)
        {
            var user  = _database.AspNetUsers.Find(userId);
            var roles = user.AspNetRoles;

            foreach (var role in roles)
            {
                roles.Remove(role);
            }
            return(_database.SaveChanges());
        }