Skip to content

Commit

Permalink
ASC.Files: FolderDao: additional null checks
Browse files Browse the repository at this point in the history
  • Loading branch information
andreysavihin committed Nov 13, 2024
1 parent 125968b commit f410b1e
Showing 1 changed file with 29 additions and 12 deletions.
41 changes: 29 additions & 12 deletions products/ASC.Files/Core/Core/Dao/TeamlabDao/FolderDao.cs
Original file line number Diff line number Diff line change
Expand Up @@ -568,41 +568,58 @@ private async Task<int> InternalSaveFolderToDbAsync(FilesDbContext filesDbContex

public async Task<int> SetWatermarkSettings(WatermarkSettings watermarkSettings, Folder<int> room)
{
ArgumentNullException.ThrowIfNull(room);

var tenantId = await _tenantManager.GetCurrentTenantIdAsync();

await using var filesDbContext = await _dbContextFactory.CreateDbContextAsync();
var roomSettings = await filesDbContext.RoomSettingsAsync(tenantId, room.Id);

var toUpdate = await filesDbContext.RoomSettingsAsync(tenantId, room.Id);

toUpdate.Watermark = mapper.Map<WatermarkSettings, DbRoomWatermark>(watermarkSettings);
filesDbContext.Update(toUpdate);

await filesDbContext.SaveChangesAsync();
if (roomSettings != null)
{
roomSettings.Watermark = mapper.Map<WatermarkSettings, DbRoomWatermark>(watermarkSettings);
filesDbContext.Update(roomSettings);
await filesDbContext.SaveChangesAsync();
}

return room.Id;
}

public async Task<Folder<int>> DeleteWatermarkSettings(Folder<int> room)
{
ArgumentNullException.ThrowIfNull(room);

var tenantId = await _tenantManager.GetCurrentTenantIdAsync();

await using var filesDbContext = await _dbContextFactory.CreateDbContextAsync();
var roomSettings = await filesDbContext.RoomSettingsAsync(tenantId, room.Id);
roomSettings.Watermark = null;
filesDbContext.Update(roomSettings);
await filesDbContext.SaveChangesAsync();

if (roomSettings != null)
{
roomSettings.Watermark = null;
filesDbContext.Update(roomSettings);
await filesDbContext.SaveChangesAsync();
}

return room;
}

public async Task<Folder<int>> DeleteLifetimeSettings(Folder<int> room)
{
ArgumentNullException.ThrowIfNull(room);

var tenantId = await _tenantManager.GetCurrentTenantIdAsync();

await using var filesDbContext = await _dbContextFactory.CreateDbContextAsync();
var roomSettings = await filesDbContext.RoomSettingsAsync(tenantId, room.Id);
roomSettings.Lifetime = null;
filesDbContext.Update(roomSettings);
await filesDbContext.SaveChangesAsync();

if (roomSettings != null)
{
roomSettings.Lifetime = null;
filesDbContext.Update(roomSettings);
await filesDbContext.SaveChangesAsync();
}

return room;
}

Expand Down

0 comments on commit f410b1e

Please sign in to comment.