исправление ошибок в методах

This commit is contained in:
eugeniy_ivanov 2023-02-14 18:36:25 +05:00
parent 2b02bdb0b8
commit 96dae2f247

View File

@ -62,11 +62,12 @@ namespace AsbCloudInfrastructure.Repository
var users = await GetCacheUserAsync(token); var users = await GetCacheUserAsync(token);
if (users is null) if (users is null)
return Enumerable.Empty<UserExtendedDto>(); return Enumerable.Empty<UserExtendedDto>();
var dtos = users var dtos = new List<UserExtendedDto>();
.Select(d => Convert(d)); foreach(var user in users)
foreach(var dto in dtos)
{ {
dto.RoleNames = GetRolesNamesByIdUser(dto.Id); var dto = Convert(user);
dto.RoleNames = GetRolesNamesByIdUser(user.Id);
dtos.Add(dto);
}; };
return dtos; return dtos;
} }
@ -111,6 +112,7 @@ namespace AsbCloudInfrastructure.Repository
if (entity is null) if (entity is null)
return -1; return -1;
entity.Id = dto.Id; entity.Id = dto.Id;
entity.Login = dto.Login;
entity.Name = dto.Name; entity.Name = dto.Name;
entity.Email = dto.Email; entity.Email = dto.Email;
entity.Phone = dto.Phone; entity.Phone = dto.Phone;
@ -129,10 +131,17 @@ namespace AsbCloudInfrastructure.Repository
var user = (await GetCacheUserAsync(token)).FirstOrDefault(u => u.Id == id); var user = (await GetCacheUserAsync(token)).FirstOrDefault(u => u.Id == id);
if (user is null) if (user is null)
return 0; return 0;
var result = dbContext.Users.Remove(user); var query = dbContext
await dbContext.SaveChangesAsync(token); .Users
DropCacheUsers(); .Where(u => u.Id == id);
return result.Entity.Id; if (query.Any())
{
var result = dbContext.Users.Remove(query.First());
await dbContext.SaveChangesAsync(token);
DropCacheUsers();
return result.Entity.Id;
}
return -1;
} }
public IEnumerable<UserRoleDto> GetRolesByIdUser(int idUser, int nestedLevel = 0) public IEnumerable<UserRoleDto> GetRolesByIdUser(int idUser, int nestedLevel = 0)
@ -168,9 +177,14 @@ namespace AsbCloudInfrastructure.Repository
} }
private IEnumerable<string> GetRolesNamesByIdUser(int idUser) private IEnumerable<string> GetRolesNamesByIdUser(int idUser)
=> GetRolesByIdUser(idUser, 7) {
.Select(r => r.Caption) var userRoles = GetRolesByIdUser(idUser, 7)
.Distinct(); .Select(r => r.Caption)
.Distinct();
if (userRoles.Any())
return userRoles;
return Enumerable.Empty<string>();
}
private async Task AssertLoginIsBusyAsync(string login, CancellationToken token) private async Task AssertLoginIsBusyAsync(string login, CancellationToken token)
{ {
@ -184,7 +198,7 @@ namespace AsbCloudInfrastructure.Repository
private IEnumerable<RelationUserUserRole> GetCachRelationUserUserRoleCacheTag() private IEnumerable<RelationUserUserRole> GetCachRelationUserUserRoleCacheTag()
{ {
var cache = memoryCache.GetOrCreate(userCacheTag, cacheEntry => var cache = memoryCache.GetOrCreate(relationUserUserRoleCacheTag, cacheEntry =>
{ {
cacheEntry.AbsoluteExpirationRelativeToNow = cacheObsolence; cacheEntry.AbsoluteExpirationRelativeToNow = cacheObsolence;
cacheEntry.SlidingExpiration = cacheObsolence; cacheEntry.SlidingExpiration = cacheObsolence;