/// <summary> /// 为某个组织创建某个角色 /// </summary> /// <param name="json"></param> /// <param name="orgId"></param> /// <returns></returns> public async Task CreateByOrgId(RoleJson json, string orgId) { // 1. 创建角色 string roleId = Guid.NewGuid().ToString(); json.Id = roleId; await Store.Create(Mapper.Map <Role>(json)); // 2. 创建角色组织关联 await RoleOrgStore.Create(new RoleOrg { Id = Guid.NewGuid().ToString(), RoleId = roleId, OrgId = orgId }); }
/// <summary> /// 新增角色 -通过组织用户ID(UID-[UO]->OID|RID-->RO) /// 将角色添加到用户所在组织上 /// </summary> /// <param name="json">新增角色</param> /// <param name="userId">用户ID</param> /// <returns></returns> public async Task CreateForOrgByUserId(RoleJson json, string userId) { // 1. 创建角色 string roleId = Guid.NewGuid().ToString(); json.Id = roleId; await Store.Create(Mapper.Map <Role>(json)); // 2. 通过用户ID查询组织ID -用户不能有多个组织 var orgId = (from uo in Store.Context.UserOrgs where uo.UserId == userId select uo.OrgId).Single(); // TODO:角色名称不能重复 // 3. 创建角色组织关联 await RoleOrgStore.Create(new RoleOrg { Id = Guid.NewGuid().ToString(), RoleId = roleId, OrgId = orgId }); }