public async Task AddRoleAsync(AddRoleModel model)
        {
            var role = model.CopyProperties <Role>();

            role.ID = Guid.NewGuid();
            AddRoleWebMenus(role, model.WebMenuIDs);
            _authorityUnitOfWork.RegisterAdd(role);
            await _authorityUnitOfWork.CommitAsync();
        }
示例#2
0
        public async Task AddWebMenuAsync(AddWebMenuModel model)
        {
            var webMenu = model.CopyProperties <WebMenu>();

            webMenu.Index = _webMenuRepository.GetMaxIndex() + 1;
            _authorityUnitOfWork.RegisterAdd(webMenu);
            await _authorityUnitOfWork.CommitAsync();
        }
        public async Task AddUserAsync(AddUserModel model)
        {
            if (await _userRepository.ExistedAsync(m => m.Account.Equals(model.Account)))
            {
                throw new MateralConfigCenterException("账号已存在");
            }
            var user = model.CopyProperties <User>();

            user.Password = PasswordHelper.GetEncodePassword(string.IsNullOrEmpty(model.Password) ? "123456" : user.Password);
            _authorityUnitOfWork.RegisterAdd(user);
            await _authorityUnitOfWork.CommitAsync();
        }
示例#4
0
        public async Task AddUserAsync(AddUserModel model)
        {
            if (string.IsNullOrEmpty(model.Name))
            {
                throw new InvalidOperationException("名称为空");
            }
            if (!string.IsNullOrEmpty(model.Account) && await _userRepository.CountAsync(m => m.Account == model.Account) > 0)
            {
                throw new InvalidOperationException("账户重复");
            }
            var user = model.CopyProperties <User>();

            user.Password = GetEncodePassword(DefaultPassword);
            AddUserRoles(user, model.RoleIDs);
            _authorityUnitOfWork.RegisterAdd(user);
            await _authorityUnitOfWork.CommitAsync();
        }
        public async Task AddWebMenuAuthorityAsync(AddWebMenuAuthorityModel model)
        {
            if (string.IsNullOrEmpty(model.Name))
            {
                throw new InvalidOperationException("名称为空");
            }
            if (!string.IsNullOrEmpty(model.Code) && await _webMenuAuthorityRepository.CountAsync(m => m.Code == model.Code) > 0)
            {
                throw new InvalidOperationException("代码重复");
            }
            var webMenuAuthority = model.CopyProperties <WebMenuAuthority>();

            webMenuAuthority.Index = _webMenuAuthorityRepository.GetMaxIndex() + 1;
            _authorityUnitOfWork.RegisterAdd(webMenuAuthority);
            await _authorityUnitOfWork.CommitAsync();

            _webMenuAuthorityRepository.ClearCache();
        }
        public async Task AddSubSystemAsync(AddSubSystemModel model)
        {
            SubSystem subSystemFromDB = await _subSystemRepository.FirstOrDefaultAsync(m => m.Name == model.Name);

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

            if (subSystemFromDB != null)
            {
                throw new InvalidOperationException("子系统代码已存在");
            }
            subSystemFromDB       = model.CopyProperties <SubSystem>();
            subSystemFromDB.Index = _subSystemRepository.GetMaxIndex() + 1;
            _authorityUnitOfWork.RegisterAdd(subSystemFromDB);
            await _authorityUnitOfWork.CommitAsync();
        }
        public async Task AddAPIAuthorityAsync(AddAPIAuthorityModel model)
        {
            if (string.IsNullOrEmpty(model.Code))
            {
                throw new InvalidOperationException("代码为空");
            }
            if (string.IsNullOrEmpty(model.Name))
            {
                throw new InvalidOperationException("名称为空");
            }
            if (await _apiAuthorityRepository.CountAsync(m => m.Code == model.Code) > 0)
            {
                throw new InvalidOperationException("代码重复");
            }
            var apiAuthority = model.CopyProperties <APIAuthority>();

            _authorityUnitOfWork.RegisterAdd(apiAuthority);
            await _authorityUnitOfWork.CommitAsync();

            _apiAuthorityRepository.ClearCache();
        }
示例#8
0
        public async Task AddActionAuthorityAsync(AddActionAuthorityModel 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.Code == model.Code && m.ActionGroupCode == model.ActionGroupCode) > 0)
            {
                throw new InvalidOperationException("同一个功能组下只允许存在一个唯一的代码");
            }
            var actionAuthority = model.CopyProperties <ActionAuthority>();

            _authorityUnitOfWork.RegisterAdd(actionAuthority);
            await _authorityUnitOfWork.CommitAsync();
        }
示例#9
0
        public async Task AddRoleAsync(AddRoleModel model)
        {
            if (string.IsNullOrEmpty(model.Code))
            {
                throw new InvalidOperationException("代码为空");
            }
            if (string.IsNullOrEmpty(model.Name))
            {
                throw new InvalidOperationException("名称为空");
            }
            if (await _roleRepository.CountAsync(m => m.Code == model.Code) > 0)
            {
                throw new InvalidOperationException("代码重复");
            }
            var role = model.CopyProperties <Role>();

            AddRoleActionAuthorities(role, model.ActionAuthorityIDs);
            AddRoleAPIAuthorities(role, model.APIAuthorityIDs);
            AddRoleWebMenuAuthorities(role, model.WebMenuAuthorityIDs);
            _authorityUnitOfWork.RegisterAdd(role);
            await _authorityUnitOfWork.CommitAsync();

            _roleRepository.ClearCache();
        }