Ejemplo n.º 1
0
        private async Task InitRoleAsync()
        {
            if (await _roleRepository.GetCountAsync() == 0)
            {
                var role = await _roleRepository.InsertAsync(new Role
                {
                    Name        = "超级管理员",
                    Description = "权限最大,拥有所有权限"
                });

                var manager = await _managerRepository.InsertAsync(new Manager(Guid.NewGuid(), "admin", "123456", ""));

                await _managerRoleRepository.InsertAsync(ManagerRole.CreateManagerRole(manager, role));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 给用户赋予新的角色
        /// </summary>
        /// <param name="role"></param>
        /// <param name="menus"></param>
        /// <returns></returns>
        public async Task AddRoleToManager(Guid guid, List <Guid> roleIdList)
        {
            var manager = await _managerRepository.GetAsync(x => x.Id == guid);

            //删除所有的原有权限
            await _managerRoleRepository.DeleteAsync(x => x.ManagerId == manager.Id);

            //赋予权限
            foreach (var roleId in roleIdList)
            {
                var role = await _roleRepository.FindAsync(x => x.Id == roleId);

                if (role == null)
                {
                    continue;
                }
                var roleMenu = ManagerRole.CreateManagerRole(manager, role);
                await _managerRoleRepository.InsertAsync(roleMenu);
            }
        }