Пример #1
0
        //public IQueryable<RoleClaim> QueryRoleClaims()
        //{
        //    return _db.RoleClaims.AsQueryable();
        //}
        /// <summary>
        /// Delete all LDAP Mappings for a role
        /// </summary>
        /// <param name="role"></param>
        /// <returns></returns>
        public async Task <IdentityResult> DeleteLdapMappingAsync(string roleId)
        {
            Ensure.Argument.NotNull(roleId, "role Id");
            var result   = new IdentityResult();
            var mappings = await _db.LdapMappings.Where(x => x.RoleId == roleId).ToListAsync();

            _db.LdapMappings.RemoveRange(mappings);
            _db.SaveChanges();

            result = IdentityResult.Success;

            return(result);
        }
Пример #2
0
        public async Task <IdentityResult> RemoveFromRoleAsync(User user, Role role)
        {
            if (user == null || user.Id == null)
            {
                return(Failure("Cannot upate user roles. User or Id cannot be null."));
            }
            if (role == null || role.Id == null)
            {
                return(Failure("Cannot upate user roles. Role or Id cannot be null."));
            }

            var existingUserRole = await _db.UserRoles.FirstOrDefaultAsync(x => x.RoleId == role.Id && x.UserId == user.Id);

            if (existingUserRole != null)
            {
                _db.UserRoles.Remove(existingUserRole);
                _db.SaveChanges();
            }


            return(IdentityResult.Success);
        }