Occupancy script udpate

This commit is contained in:
Justinas K. 2021-12-06 13:32:25 +02:00
parent 118e66ceca
commit 30194d5832
1 changed files with 21 additions and 14 deletions

View File

@ -241,25 +241,32 @@ private async Task EvaluateOccupancyAsync(Tenant tenant, int newOccupancyValue,
private async Task AddRemoveOccupancyAccessLevelAsync(int tenantId, bool remove)
{
var filterId = await CreateCompanyFilterAsync(tenantId);
int filterId = await CreateCompanyFilterAsync(tenantId);
try
{
await Context.BulkUpdateUsersAsync(0, 1000, Array.Empty<int>(), new BulkUpdateUser
{
AccessLevels =
IEnumerable<Grpc.AccessLevel> als = await Context.GetAccessLevelsAsync();
List<EntityUpdate> toUpdate = als.Where(e => e.Id != Configuration.AccessLevelId).Select(e =>
new EntityUpdate()
{
new EntityUpdate[]
{
new()
{
Id = Configuration.AccessLevelId,
Remove = remove,
Update = true
}
}
Id = e.Id,
Remove = false,
Update = false
}).ToList();
toUpdate.Add(new EntityUpdate
{
Id = Configuration.AccessLevelId,
Remove = remove,
Update = true
}
}, filterId);
);
var bulkUpdateUserRequest = new BulkUpdateUser();
bulkUpdateUserRequest.AccessLevels.AddRange(toUpdate);
await Context.BulkUpdateUsersAsync(0, 100000, Array.Empty<int>(), bulkUpdateUserRequest, filterId);
}
finally
{