forked from ddrilling/AsbCloudServer
исправление ошибок в методах
This commit is contained in:
parent
2b02bdb0b8
commit
96dae2f247
@ -62,11 +62,12 @@ namespace AsbCloudInfrastructure.Repository
|
||||
var users = await GetCacheUserAsync(token);
|
||||
if (users is null)
|
||||
return Enumerable.Empty<UserExtendedDto>();
|
||||
var dtos = users
|
||||
.Select(d => Convert(d));
|
||||
foreach(var dto in dtos)
|
||||
var dtos = new List<UserExtendedDto>();
|
||||
foreach(var user in users)
|
||||
{
|
||||
dto.RoleNames = GetRolesNamesByIdUser(dto.Id);
|
||||
var dto = Convert(user);
|
||||
dto.RoleNames = GetRolesNamesByIdUser(user.Id);
|
||||
dtos.Add(dto);
|
||||
};
|
||||
return dtos;
|
||||
}
|
||||
@ -111,6 +112,7 @@ namespace AsbCloudInfrastructure.Repository
|
||||
if (entity is null)
|
||||
return -1;
|
||||
entity.Id = dto.Id;
|
||||
entity.Login = dto.Login;
|
||||
entity.Name = dto.Name;
|
||||
entity.Email = dto.Email;
|
||||
entity.Phone = dto.Phone;
|
||||
@ -129,10 +131,17 @@ namespace AsbCloudInfrastructure.Repository
|
||||
var user = (await GetCacheUserAsync(token)).FirstOrDefault(u => u.Id == id);
|
||||
if (user is null)
|
||||
return 0;
|
||||
var result = dbContext.Users.Remove(user);
|
||||
await dbContext.SaveChangesAsync(token);
|
||||
DropCacheUsers();
|
||||
return result.Entity.Id;
|
||||
var query = dbContext
|
||||
.Users
|
||||
.Where(u => u.Id == 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)
|
||||
@ -168,9 +177,14 @@ namespace AsbCloudInfrastructure.Repository
|
||||
}
|
||||
|
||||
private IEnumerable<string> GetRolesNamesByIdUser(int idUser)
|
||||
=> GetRolesByIdUser(idUser, 7)
|
||||
.Select(r => r.Caption)
|
||||
.Distinct();
|
||||
{
|
||||
var userRoles = GetRolesByIdUser(idUser, 7)
|
||||
.Select(r => r.Caption)
|
||||
.Distinct();
|
||||
if (userRoles.Any())
|
||||
return userRoles;
|
||||
return Enumerable.Empty<string>();
|
||||
}
|
||||
|
||||
private async Task AssertLoginIsBusyAsync(string login, CancellationToken token)
|
||||
{
|
||||
@ -184,7 +198,7 @@ namespace AsbCloudInfrastructure.Repository
|
||||
|
||||
private IEnumerable<RelationUserUserRole> GetCachRelationUserUserRoleCacheTag()
|
||||
{
|
||||
var cache = memoryCache.GetOrCreate(userCacheTag, cacheEntry =>
|
||||
var cache = memoryCache.GetOrCreate(relationUserUserRoleCacheTag, cacheEntry =>
|
||||
{
|
||||
cacheEntry.AbsoluteExpirationRelativeToNow = cacheObsolence;
|
||||
cacheEntry.SlidingExpiration = cacheObsolence;
|
||||
|
Loading…
Reference in New Issue
Block a user