Ejemplo n.º 1
0
        public void SetUserRole(string userId, List <string> roleIds)
        {
            Service.Delete_Sql <Base_UserRoleMap>(x => x.UserId == userId);
            var insertList = roleIds.Select(x => new Base_UserRoleMap
            {
                Id     = GuidHelper.GenerateKey(),
                UserId = userId,
                RoleId = x
            }).ToList();

            Service.Insert(insertList);
            _cache.UpdateCache(userId);
            PermissionManage.UpdateUserPermissionCache(userId);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 保存权限
        /// </summary>
        /// <param name="roleId">角色Id</param>
        /// <param name="permissions">权限值</param>
        public void SavePermission(string roleId, List <string> permissions)
        {
            Service.Delete_Sql <Base_PermissionRole>(x => x.RoleId == roleId);
            List <Base_PermissionRole> insertList = new List <Base_PermissionRole>();

            permissions.ForEach(newPermission =>
            {
                insertList.Add(new Base_PermissionRole
                {
                    Id              = Guid.NewGuid().ToSequentialGuid(),
                    RoleId          = roleId,
                    PermissionValue = newPermission
                });
            });

            Service.Insert(insertList);
            PermissionManage.ClearUserPermissionCache();
        }