示例#1
0
        /// <summary>
        /// 创建角色
        /// </summary>
        /// <param name="request">创建角色参数</param>
        public async Task <Guid> CreateAsync(CreateRoleRequest request)
        {
            var role = request.MapTo <Role>();
            await RoleManager.CreateAsync(role);

            await UnitOfWork.CommitAsync();

            return(role.Id);
        }
示例#2
0
        /// <summary>
        /// 创建角色
        /// </summary>
        /// <param name="request">创建角色请求</param>
        public async Task <Guid> CreateAsync(CreateRoleRequest request)
        {
            var role = request.MapTo <Role>();

            if (request.Type == RoleTypeCode.TenantRole)
            {
                var tenantRole = await RoleRepository.GetByCodeAsync(RoleCode.TenantAdmin);

                if (tenantRole == null)
                {
                    throw new Warning("找不到租户角色,请联系管理员");
                }
                role.ParentId = tenantRole.Id;
            }

            await RoleManager.CreateAsync(role);

            await UnitOfWork.CommitAsync();

            return(role.Id);
        }
示例#3
0
 /// <summary>
 /// 转换为实体
 /// </summary>
 protected Role ToEntity(CreateRoleRequest request)
 {
     return(request.MapTo <Role>());
 }