private async Task CreateOrRemoveRelationRoleEmployee(EmployeeRequestDto employeeRequestDto) { var empRole = await _relationEmployeeRoleAppService.GetRoleIdsByEmployeeIds(new List <string>() { employeeRequestDto.Id }); var dbRoleIds = empRole.Select(r => r.RoleId).ToList(); var addRoleIds = employeeRequestDto.RoleIds.Except(dbRoleIds); var removeRoleIds = dbRoleIds.Except(employeeRequestDto.RoleIds); var addRelationRoleEmp = addRoleIds.Select(o => new RelationEmployeeRoleRequestDto { Id = Guid.NewGuid().ToString(), RoleId = o, EmployeeId = employeeRequestDto.Id, CreateUserId = employeeRequestDto.CreateUserId, CreateUserName = employeeRequestDto.CreateUserName }); await _relationEmployeeRoleAppService.BatchCreateAsync(addRelationRoleEmp.ToList()); var removeRelationRoleEmp = new RelationEmployeeRoleRemoveDto { EmployeeId = employeeRequestDto.Id, RoleIds = removeRoleIds.ToList(), ModifyUserId = employeeRequestDto.ModifyUserId, ModifyUserName = employeeRequestDto.ModifyUserName, ModifyDate = DateTime.Now }; await _relationEmployeeRoleAppService.RemoveByEmployeeIdAndRoleIds(removeRelationRoleEmp); }
/// <summary> /// 根据成员Id和角色ids删除 /// </summary> /// <param name="relationEmployeeRoleRemoveDto"></param> /// <returns></returns> public async Task <bool> RemoveByEmployeeIdAndRoleIds(RelationEmployeeRoleRemoveDto relationEmployeeRoleRemoveDto) { return(await _relationEmployeeRoleRespository.UpdateAsync(r => r.EmployeeId == relationEmployeeRoleRemoveDto.EmployeeId && relationEmployeeRoleRemoveDto.RoleIds.Contains(r.RoleId), async (e) => { await Task.Run(() => { e.IsDelete = true; e.ModifyUserId = relationEmployeeRoleRemoveDto.ModifyUserId; e.ModifyUserName = relationEmployeeRoleRemoveDto.ModifyUserName; e.ModifyDate = relationEmployeeRoleRemoveDto.ModifyDate; }); })); }