если пользователь не найден в контексте

возвращается ArgumentInvalidException
This commit is contained in:
eugeniy_ivanov 2023-02-15 11:44:20 +05:00
parent d2729c3a80
commit dbbd4d5603

View File

@ -96,7 +96,8 @@ namespace AsbCloudInfrastructure.Repository
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));
throw new ArgumentInvalidException
($"Invalid id {dto.Id}. You can't edit this user.", nameof(dto));
var oldUser = (await GetCacheUserAsync(token)).FirstOrDefault(u => u.Id == dto.Id);
if (oldUser is null)
@ -110,7 +111,8 @@ namespace AsbCloudInfrastructure.Repository
var entity = dbContext.Users.FirstOrDefault(u => u.Id == dto.Id);
if (entity is null)
return -1;
throw new ArgumentInvalidException
($"Invalid id {dto.Id}. You can't edit this user.", nameof(dto));
entity.Id = dto.Id;
entity.Login = dto.Login;
entity.Name = dto.Name;
@ -141,7 +143,8 @@ namespace AsbCloudInfrastructure.Repository
DropCacheUsers();
return result.Entity.Id;
}
return -1;
throw new ArgumentInvalidException
($"Invalid id {id}. You can't edit this user.", nameof(id));
}
public IEnumerable<UserRoleDto> GetRolesByIdUser(int idUser, int nestedLevel = 0)