From 1f70868120ae7ef58af9fa8b99ab407baef70809 Mon Sep 17 00:00:00 2001 From: "ai.astrakhantsev" Date: Wed, 14 Dec 2022 10:38:44 +0500 Subject: [PATCH] #8242403 fix --- .../Repository/UserRepository.cs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/AsbCloudInfrastructure/Repository/UserRepository.cs b/AsbCloudInfrastructure/Repository/UserRepository.cs index 3a52d030..efc0db16 100644 --- a/AsbCloudInfrastructure/Repository/UserRepository.cs +++ b/AsbCloudInfrastructure/Repository/UserRepository.cs @@ -35,27 +35,28 @@ namespace AsbCloudInfrastructure.Repository this.userRoleRepository = userRoleRepository; } - public async Task InsertAsync(UserExtendedDto dto, CancellationToken token = default) + public async Task InsertAsync(UserExtendedDto dto, CancellationToken token) { dto.Id = default; var entity = Convert(dto); await AssertLoginIsBusyAsync(dto.Login, token); var userRoles = await userRoleRepository.GetByNamesAsync(dto.RoleNames, token).ConfigureAwait(false); var updatedEntity = await dbContext.Users.AddAsync(entity, token).ConfigureAwait(false); + await dbContext.SaveChangesAsync(token); + if (userRoles?.Any() == true) await UpdateRolesCacheForUserAsync(updatedEntity.Entity.Id, userRoles, token); - await dbContext.SaveChangesAsync(token); DropCacheUsers(); return updatedEntity.Entity.Id; } - public Task InsertRangeAsync(IEnumerable newItems, CancellationToken token = default) + public Task InsertRangeAsync(IEnumerable newItems, CancellationToken token) { throw new NotImplementedException(); } - public async Task> GetAllAsync(CancellationToken token = default) + public async Task> GetAllAsync(CancellationToken token) { var dtos = (await GetCacheUserAsync(token)).ToList(); if (dtos is null) @@ -76,7 +77,7 @@ namespace AsbCloudInfrastructure.Repository return dto; } - public async Task GetOrDefaultAsync(int id, CancellationToken token = default) + public async Task GetOrDefaultAsync(int id, CancellationToken token) { var dto = (await GetCacheUserAsync(token)).FirstOrDefault(u => u.Id == id); if (dto is null) @@ -86,7 +87,7 @@ namespace AsbCloudInfrastructure.Repository return dto; } - public async Task UpdateAsync(UserExtendedDto dto, CancellationToken token = default) + public async Task UpdateAsync(UserExtendedDto dto, CancellationToken token) { if (dto.Id <= 1) throw new ArgumentInvalidException($"Invalid id {dto.Id}. You can't edit this user.", nameof(dto)); @@ -109,7 +110,7 @@ namespace AsbCloudInfrastructure.Repository return result.Entity.Id; } - public async Task DeleteAsync(int id, CancellationToken token = default) + public async Task DeleteAsync(int id, CancellationToken token) { var dto = (await GetCacheUserAsync(token)).FirstOrDefault(u => u.Id == id); if (dto is null) @@ -159,7 +160,7 @@ namespace AsbCloudInfrastructure.Repository .Select(r => r.Caption) .Distinct(); - private async Task AssertLoginIsBusyAsync(string login, CancellationToken token = default) + private async Task AssertLoginIsBusyAsync(string login, CancellationToken token) { var existingUserDto = (await GetCacheUserAsync(token)) .FirstOrDefault(u => u.Login.ToLower() == login.ToLower());