Exemplo n.º 1
0
        public async Task EditAPIAuthorityAsync(EditAPIAuthorityModel model)
        {
            if (string.IsNullOrEmpty(model.Code))
            {
                throw new InvalidOperationException("代码为空");
            }
            if (string.IsNullOrEmpty(model.Name))
            {
                throw new InvalidOperationException("名称为空");
            }
            if (await _apiAuthorityRepository.CountAsync(m => m.ID != model.ID && m.Code == model.Code) > 0)
            {
                throw new InvalidOperationException("代码重复");
            }
            APIAuthority apiAuthorityFromDB = await _apiAuthorityRepository.FirstOrDefaultAsync(model.ID);

            if (apiAuthorityFromDB == null)
            {
                throw new InvalidOperationException("API权限不存在");
            }
            model.CopyProperties(apiAuthorityFromDB);
            apiAuthorityFromDB.UpdateTime = DateTime.Now;
            _authorityUnitOfWork.RegisterEdit(apiAuthorityFromDB);
            await _authorityUnitOfWork.CommitAsync();

            _apiAuthorityRepository.ClearCache();
        }
Exemplo n.º 2
0
        public async Task EditRoleAsync(EditRoleModel model)
        {
            if (string.IsNullOrEmpty(model.Code))
            {
                throw new InvalidOperationException("代码为空");
            }
            if (string.IsNullOrEmpty(model.Name))
            {
                throw new InvalidOperationException("名称为空");
            }
            if (await _roleRepository.CountAsync(m => m.ID != model.ID && m.Code == model.Code) > 0)
            {
                throw new InvalidOperationException("代码重复");
            }
            Role roleFromDB = await _roleRepository.FirstOrDefaultAsync(model.ID);

            if (roleFromDB == null)
            {
                throw new InvalidOperationException("角色不存在");
            }
            model.CopyProperties(roleFromDB);
            await EditRoleActionAuthorities(roleFromDB, model.ActionAuthorityIDs);
            await EditRoleAPIAuthorities(roleFromDB, model.APIAuthorityIDs);
            await EditRoleWebMenuAuthorities(roleFromDB, model.WebMenuAuthorityIDs);

            _authorityUnitOfWork.RegisterEdit(roleFromDB);
            await _authorityUnitOfWork.CommitAsync();

            _roleRepository.ClearCache();
        }
        public async Task EditSubSystemAsync(EditSubSystemModel model)
        {
            SubSystem subSystemFromDB = await _subSystemRepository.FirstOrDefaultAsync(m => m.Name == model.Name && m.ID != model.ID);

            if (subSystemFromDB != null)
            {
                throw new InvalidOperationException("子系统代码已存在");
            }
            subSystemFromDB = await _subSystemRepository.FirstOrDefaultAsync(m => m.Code == model.Code && m.ID != model.ID);

            if (subSystemFromDB != null)
            {
                throw new InvalidOperationException("子系统代码已存在");
            }
            subSystemFromDB = await _subSystemRepository.FirstOrDefaultAsync(model.ID);

            if (subSystemFromDB == null)
            {
                throw new InvalidOperationException("子系统不存在");
            }
            model.CopyProperties(subSystemFromDB);
            subSystemFromDB.UpdateTime = DateTime.Now;
            _authorityUnitOfWork.RegisterEdit(subSystemFromDB);
            await _authorityUnitOfWork.CommitAsync();
        }
Exemplo n.º 4
0
        public async Task EditWebMenuAsync(EditWebMenuModel model)
        {
            WebMenu webMenuFromDB = await _webMenuRepository.FirstOrDefaultAsync(model.ID);

            if (webMenuFromDB == null)
            {
                throw new InvalidOperationException("网页菜单权限不存在");
            }
            model.CopyProperties(webMenuFromDB);
            webMenuFromDB.UpdateTime = DateTime.Now;
            _authorityUnitOfWork.RegisterEdit(webMenuFromDB);
            await _authorityUnitOfWork.CommitAsync();
        }
Exemplo n.º 5
0
        public async Task EditRoleAsync(EditRoleModel model)
        {
            Role roleFromDB = await _roleRepository.FirstOrDefaultAsync(model.ID);

            if (roleFromDB == null)
            {
                throw new InvalidOperationException("角色不存在");
            }
            model.CopyProperties(roleFromDB);
            roleFromDB.UpdateTime = DateTime.Now;
            await EditRoleWebMenus(roleFromDB, model.WebMenuIDs);

            _authorityUnitOfWork.RegisterEdit(roleFromDB);
            await _authorityUnitOfWork.CommitAsync();
        }
Exemplo n.º 6
0
        public async Task EditActionAuthorityAsync(EditActionAuthorityModel model)
        {
            if (string.IsNullOrEmpty(model.ActionGroupCode))
            {
                throw new InvalidOperationException("功能组标识为空");
            }
            if (string.IsNullOrEmpty(model.Code))
            {
                throw new InvalidOperationException("代码为空");
            }
            if (string.IsNullOrEmpty(model.Name))
            {
                throw new InvalidOperationException("名称为空");
            }
            if (await _actionAuthorityRepository.CountAsync(m => m.ID != model.ID && m.Code == model.Code && m.ActionGroupCode == model.ActionGroupCode) > 0)
            {
                throw new InvalidOperationException("同一个功能组下只允许存在一个唯一的代码");
            }
            ActionAuthority actionAuthorityFromDB = await _actionAuthorityRepository.FirstOrDefaultAsync(model.ID);

            if (actionAuthorityFromDB == null)
            {
                throw new InvalidOperationException("功能权限不存在");
            }
            model.CopyProperties(actionAuthorityFromDB);
            _authorityUnitOfWork.RegisterEdit(actionAuthorityFromDB);
            await _authorityUnitOfWork.CommitAsync();
        }
Exemplo n.º 7
0
        public async Task EditUserAsync(EditUserModel model)
        {
            if (string.IsNullOrEmpty(model.Name))
            {
                throw new InvalidOperationException("名称为空");
            }
            if (await _userRepository.CountAsync(m => m.ID != model.ID && m.Account == model.Account) > 0)
            {
                throw new InvalidOperationException("账户重复");
            }
            User userFromDB = await _userRepository.FirstOrDefaultAsync(model.ID);

            if (userFromDB == null)
            {
                throw new InvalidOperationException("用户不存在");
            }
            model.CopyProperties(userFromDB);
            await EditUserRoles(userFromDB, model.RoleIDs);

            _authorityUnitOfWork.RegisterEdit(userFromDB);
            await _authorityUnitOfWork.CommitAsync();
        }
Exemplo n.º 8
0
        public async Task EditUserAsync(EditUserModel model)
        {
            if (await _userRepository.ExistedAsync(m => m.Account.Equals(model.Account) && m.ID != model.ID))
            {
                throw new MateralConfigCenterException("账号已存在");
            }
            User userFromDb = await _userRepository.FirstOrDefaultAsync(model.ID);

            if (userFromDb == null)
            {
                throw new MateralConfigCenterException("用户不存在");
            }
            string oldPassword = userFromDb.Password;

            model.CopyProperties(userFromDb);
            userFromDb.Password   = string.IsNullOrEmpty(model.Password) ? oldPassword : PasswordHelper.GetEncodePassword(model.Password);
            userFromDb.UpdateTime = DateTime.Now;
            _authorityUnitOfWork.RegisterEdit(userFromDb);
            await _authorityUnitOfWork.CommitAsync();
        }