Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexMi-Ha committed Apr 23, 2024
1 parent 51da594 commit 9d03b88
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions PWManager.Data/Repositories/SettingsRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 9d03b88

Please sign in to comment.