From 9d03b882a2aa23c74a3d9f4fad128dde3760d3e3 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 23 Apr 2024 11:00:00 +0200 Subject: [PATCH] Refactor --- .../Repositories/SettingsRepository.cs | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/PWManager.Data/Repositories/SettingsRepository.cs b/PWManager.Data/Repositories/SettingsRepository.cs index c431e1d..6669dcf 100644 --- a/PWManager.Data/Repositories/SettingsRepository.cs +++ b/PWManager.Data/Repositories/SettingsRepository.cs @@ -36,18 +36,20 @@ public Settings GetSettings() { var userId = _environment.CurrentUser.Id; var settingsList = _dbContext.Settings.Where(e => e.UserId == userId).AsNoTracking().ToList(); var settingsModel = settingsList.Any() ? settingsList.First() : null; - if (settingsModel is null) { - settingsModel = new SettingsModel { - UserId = _environment.CurrentUser.Id, - Id = Guid.NewGuid().ToString(), - MainGroupIdentifier = _cryptService.Encrypt("main"), - AccountTimeOutDuration = TimeSpan.FromMinutes(5), - ClipboardTimeOutDuration = TimeSpan.FromMinutes(1), - }; - _dbContext.Settings.Add(settingsModel); - _dbContext.SaveChanges(); + if (settingsModel is not null) { + return SettingsModelToEntity(settingsModel); } + settingsModel = new SettingsModel { + UserId = _environment.CurrentUser.Id, + Id = Guid.NewGuid().ToString(), + MainGroupIdentifier = _cryptService.Encrypt("main"), + AccountTimeOutDuration = TimeSpan.FromMinutes(5), + ClipboardTimeOutDuration = TimeSpan.FromMinutes(1), + }; + _dbContext.Settings.Add(settingsModel); + _dbContext.SaveChanges(); + return SettingsModelToEntity(settingsModel); }