Exemplo n.º 1
0
        public async Task DeleteRoleAsync([Required(ErrorMessage = "唯一标识不能为空")] Guid id)
        {
            Role roleFromDB = await _roleRepository.FirstOrDefaultAsync(id);

            if (roleFromDB == null)
            {
                throw new InvalidOperationException("角色不存在");
            }
            _authorityUnitOfWork.RegisterDelete(roleFromDB);
            await _authorityUnitOfWork.CommitAsync();
        }
Exemplo n.º 2
0
        /// <summary>
        /// 编辑角色功能权限
        /// </summary>
        /// <param name="role"></param>
        /// <param name="actionAuthorityIDs"></param>
        /// <returns></returns>
        private async Task EditRoleActionAuthorities(Role role, Guid[] actionAuthorityIDs)
        {
            role.RoleActionAuthorities = await _roleActionAuthorityRepository.WhereAsync(m => m.RoleID == role.ID).ToList();

            List <Guid> roleActionAuthorityIDs = role.RoleActionAuthorities.Select(m => m.ActionAuthorityID).ToList();
            List <Guid> deleteIDs = roleActionAuthorityIDs.Except(actionAuthorityIDs).ToList();
            List <RoleActionAuthority> deleteModel = role.RoleActionAuthorities.Where(m => deleteIDs.Contains(m.ActionAuthorityID)).ToList();

            foreach (RoleActionAuthority roleActionAuthority in deleteModel)
            {
                _authorityUnitOfWork.RegisterDelete(roleActionAuthority);
            }
            List <Guid> addIDs = actionAuthorityIDs.Except(roleActionAuthorityIDs).ToList();

            AddRoleActionAuthorities(role, addIDs);
        }
Exemplo n.º 3
0
        public async Task DeleteWebMenuAsync([Required(ErrorMessage = "唯一标识不能为空")] Guid id)
        {
            List <WebMenu> allWebMenus = await _webMenuRepository.FindAsync(m => true);

            WebMenu webMenuFromDB = allWebMenus.FirstOrDefault(m => m.ID == id);

            if (webMenuFromDB == null)
            {
                throw new InvalidOperationException("网页菜单权限不存在");
            }
            ICollection <WebMenu> allChild = GetAllChild(allWebMenus, id);

            foreach (WebMenu menuAuthority in allChild)
            {
                _authorityUnitOfWork.RegisterDelete(menuAuthority);
            }
            _authorityUnitOfWork.RegisterDelete(webMenuFromDB);
            await _authorityUnitOfWork.CommitAsync();
        }
Exemplo n.º 4
0
        public async Task DeleteActionAuthorityAsync(Guid id)
        {
            ActionAuthority actionAuthorityFromDB = await _actionAuthorityRepository.FirstOrDefaultAsync(id);

            if (actionAuthorityFromDB == null)
            {
                throw new InvalidOperationException("功能权限不存在");
            }
            _authorityUnitOfWork.RegisterDelete(actionAuthorityFromDB);
            await _authorityUnitOfWork.CommitAsync();
        }
        public async Task DeleteSubSystemAsync([Required(ErrorMessage = "唯一标识不能为空")] Guid id)
        {
            SubSystem subSystemFromDB = await _subSystemRepository.FirstOrDefaultAsync(id);

            if (subSystemFromDB == null)
            {
                throw new InvalidOperationException("子系统不存在");
            }
            _authorityUnitOfWork.RegisterDelete(subSystemFromDB);
            await _authorityUnitOfWork.CommitAsync();
        }
Exemplo n.º 6
0
        public async Task DeleteUserAsync([Required(ErrorMessage = "唯一标识不能为空")] Guid id)
        {
            User userFromDb = await _userRepository.FirstOrDefaultAsync(id);

            if (userFromDb == null)
            {
                throw new MateralConfigCenterException("用户不存在");
            }
            _authorityUnitOfWork.RegisterDelete(userFromDb);
            await _authorityUnitOfWork.CommitAsync();
        }
Exemplo n.º 7
0
        public async Task DeleteAPIAuthorityAsync(Guid id)
        {
            List <APIAuthority> allAPIAuthorities = await _apiAuthorityRepository.GetAllInfoFromCacheAsync();

            APIAuthority apiAuthorityFromDB = allAPIAuthorities.FirstOrDefault(m => m.ID == id);

            if (apiAuthorityFromDB == null)
            {
                throw new InvalidOperationException("API权限不存在");
            }
            ICollection <APIAuthority> allChild = GetAllChild(allAPIAuthorities, id);

            foreach (APIAuthority apiAuthority in allChild)
            {
                _authorityUnitOfWork.RegisterDelete(apiAuthority);
            }
            _authorityUnitOfWork.RegisterDelete(apiAuthorityFromDB);
            await _authorityUnitOfWork.CommitAsync();

            _apiAuthorityRepository.ClearCache();
        }
Exemplo n.º 8
0
        /// <summary>
        /// 编辑用户角色权限
        /// </summary>
        /// <param name="user"></param>
        /// <param name="roleIDs"></param>
        /// <returns></returns>
        private async Task EditUserRoles(User user, Guid[] roleIDs)
        {
            user.UserRoles = await _userRoleRepository.WhereAsync(m => m.UserID == user.ID).ToList();

            List <Guid>     userRoleIDs = user.UserRoles.Select(m => m.RoleID).ToList();
            List <Guid>     deleteIDs   = userRoleIDs.Except(roleIDs).ToList();
            List <UserRole> deleteModel = user.UserRoles.Where(m => deleteIDs.Contains(m.RoleID)).ToList();

            foreach (UserRole userRole in deleteModel)
            {
                _authorityUnitOfWork.RegisterDelete(userRole);
            }
            List <Guid> addIDs = roleIDs.Except(userRoleIDs).ToList();

            AddUserRoles(user, addIDs);
        }