From f410b1e59adf27b499959a781094edfc72ad2840 Mon Sep 17 00:00:00 2001 From: Andrey Savihin Date: Wed, 13 Nov 2024 10:29:53 +0300 Subject: [PATCH] ASC.Files: FolderDao: additional null checks --- .../Core/Core/Dao/TeamlabDao/FolderDao.cs | 41 +++++++++++++------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/products/ASC.Files/Core/Core/Dao/TeamlabDao/FolderDao.cs b/products/ASC.Files/Core/Core/Dao/TeamlabDao/FolderDao.cs index c77bd48557f..9b0d6387829 100644 --- a/products/ASC.Files/Core/Core/Dao/TeamlabDao/FolderDao.cs +++ b/products/ASC.Files/Core/Core/Dao/TeamlabDao/FolderDao.cs @@ -568,41 +568,58 @@ private async Task InternalSaveFolderToDbAsync(FilesDbContext filesDbContex public async Task SetWatermarkSettings(WatermarkSettings watermarkSettings, Folder 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); - filesDbContext.Update(toUpdate); - - await filesDbContext.SaveChangesAsync(); + if (roomSettings != null) + { + roomSettings.Watermark = mapper.Map(watermarkSettings); + filesDbContext.Update(roomSettings); + await filesDbContext.SaveChangesAsync(); + } return room.Id; } public async Task> DeleteWatermarkSettings(Folder 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> DeleteLifetimeSettings(Folder 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; }