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

возвращается 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) public async Task<int> UpdateAsync(UserExtendedDto dto, CancellationToken token)
{ {
if (dto.Id <= 1) 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); var oldUser = (await GetCacheUserAsync(token)).FirstOrDefault(u => u.Id == dto.Id);
if (oldUser is null) if (oldUser is null)
@ -110,7 +111,8 @@ namespace AsbCloudInfrastructure.Repository
var entity = dbContext.Users.FirstOrDefault(u => u.Id == dto.Id); var entity = dbContext.Users.FirstOrDefault(u => u.Id == dto.Id);
if (entity is null) 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.Id = dto.Id;
entity.Login = dto.Login; entity.Login = dto.Login;
entity.Name = dto.Name; entity.Name = dto.Name;
@ -141,7 +143,8 @@ namespace AsbCloudInfrastructure.Repository
DropCacheUsers(); DropCacheUsers();
return result.Entity.Id; 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) public IEnumerable<UserRoleDto> GetRolesByIdUser(int idUser, int nestedLevel = 0)