Exemplo n.º 1
0
        public async Task <IActionResult> InitAttachmentPowerAsync(Int32 roleId)
        {
            #region 参数验证
            Check.IfNullOrZero(roleId);
            #endregion

            var roleDto  = new RoleDto();
            var response = new ResponseModel <dynamic>();
            if (roleId != 0)
            {
                roleDto = await _securityServices.GetRoleAsync(roleId);

                if (roleDto == null)
                {
                    response.IsSuccess = true;
                    response.Message   = "获取角色失败";
                    return(Json(response));
                }
            }
            var appDtos = new List <AppDto>();
            if (roleDto.Powers.Any())
            {
                appDtos = await _appServices.GetSystemAppAsync(roleDto.Powers.Select(s => s.Id).ToArray());

                if (appDtos == null)
                {
                    response.IsSuccess = false;
                    response.Message   = "获取角色对应的系统应用失败";
                    return(Json(response));
                }
            }
            var userContext = await GetUserContextAsync();

            var uniqueToken = CreateUniqueTokenAsync(userContext.Id);

            response.Model     = new { roleDto, appDtos, uniqueToken };
            response.IsSuccess = true;
            response.Message   = "附加角色权限初始化成功";

            return(Json(response));
        }