forked from ddrilling/AsbCloudServer
#8242403 fix
This commit is contained in:
parent
bf3a910433
commit
1f70868120
@ -35,27 +35,28 @@ namespace AsbCloudInfrastructure.Repository
|
||||
this.userRoleRepository = userRoleRepository;
|
||||
}
|
||||
|
||||
public async Task<int> InsertAsync(UserExtendedDto dto, CancellationToken token = default)
|
||||
public async Task<int> 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<int> InsertRangeAsync(IEnumerable<UserExtendedDto> newItems, CancellationToken token = default)
|
||||
public Task<int> InsertRangeAsync(IEnumerable<UserExtendedDto> newItems, CancellationToken token)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<UserExtendedDto>> GetAllAsync(CancellationToken token = default)
|
||||
public async Task<IEnumerable<UserExtendedDto>> 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<UserExtendedDto?> GetOrDefaultAsync(int id, CancellationToken token = default)
|
||||
public async Task<UserExtendedDto?> 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<int> UpdateAsync(UserExtendedDto dto, CancellationToken token = default)
|
||||
public async Task<int> 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<int> DeleteAsync(int id, CancellationToken token = default)
|
||||
public async Task<int> 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());
|
||||
|
Loading…
Reference in New Issue
Block a user