forked from ddrilling/AsbCloudServer
доработка методов репозитория
This commit is contained in:
parent
95790af1f6
commit
6bf992f1f6
@ -71,7 +71,6 @@ namespace AsbCloudDb.Model
|
||||
int SaveChanges(bool acceptAllChangesOnSuccess);
|
||||
Task<int> SaveChangesAsync(CancellationToken cancellationToken);
|
||||
DbSet<TEntity> Set<TEntity>(string name) where TEntity : class;
|
||||
DbSet<TEntity> Set<TEntity>() where TEntity : class;
|
||||
EntityEntry<TEntity> Entry<TEntity>([NotNull] TEntity entity) where TEntity : class;
|
||||
DbSet<TEntity> Set<TEntity>() where TEntity : class;
|
||||
}
|
||||
}
|
@ -121,8 +121,7 @@ namespace AsbCloudInfrastructure.Repository
|
||||
entity.Patronymic = user.Patronymic;
|
||||
entity.Position = user.Position;
|
||||
entity.IdCompany = user.IdCompany;
|
||||
entity.IdState = user.IdState;
|
||||
entity.RelationUsersUserRoles = user.RelationUsersUserRoles;
|
||||
entity.IdState = user.IdState;
|
||||
await dbContext.SaveChangesAsync(token);
|
||||
}
|
||||
DropCacheUsers();
|
||||
@ -199,25 +198,19 @@ namespace AsbCloudInfrastructure.Repository
|
||||
var entities = query.ToArray();
|
||||
return entities;
|
||||
});
|
||||
return cache;
|
||||
return cache!;
|
||||
}
|
||||
private void DropCacheRelationUserUserRoleCacheTag()
|
||||
{
|
||||
memoryCache.Remove(relationUserUserRoleCacheTag);
|
||||
}
|
||||
|
||||
private async Task UpdateRolesCacheForUserAsync(int idUser, IEnumerable<UserRoleDto> newRoles, CancellationToken token)
|
||||
private async Task UpdateRolesCacheForUserAsync(int idUser, IEnumerable<UserRoleDto> roleDtos, CancellationToken token)
|
||||
{
|
||||
var relations = dbContext.RelationUserUserRoles.Where(r => r.IdUser == idUser);
|
||||
dbContext.RelationUserUserRoles.RemoveRange(relations);
|
||||
|
||||
if (newRoles?.Any() is true)
|
||||
await dbContext.RelationUserUserRoles.AddRangeAsync(newRoles.Select(role => new RelationUserUserRole
|
||||
{
|
||||
IdUser = idUser,
|
||||
IdUserRole = role.Id
|
||||
}), token).ConfigureAwait(false);
|
||||
|
||||
var entityRoles = roleDtos.Select(role => Convert(role));
|
||||
dbContext.RelationUserUserRoles.AddRange(entityRoles);
|
||||
await dbContext.SaveChangesAsync(token);
|
||||
DropCacheRelationUserUserRoleCacheTag();
|
||||
}
|
||||
@ -237,7 +230,7 @@ namespace AsbCloudInfrastructure.Repository
|
||||
var entities = query.ToArray();
|
||||
return entities;
|
||||
});
|
||||
return cache;
|
||||
return cache!;
|
||||
}
|
||||
|
||||
private Task<IEnumerable<User>> GetCacheUserAsync(CancellationToken token)
|
||||
@ -252,7 +245,7 @@ namespace AsbCloudInfrastructure.Repository
|
||||
var entities = await query.ToArrayAsync(token);
|
||||
return entities.AsEnumerable();
|
||||
});
|
||||
return cache;
|
||||
return cache!;
|
||||
}
|
||||
|
||||
protected User Convert(UserExtendedDto dto)
|
||||
@ -263,7 +256,11 @@ namespace AsbCloudInfrastructure.Repository
|
||||
return entity;
|
||||
}
|
||||
|
||||
|
||||
protected RelationUserUserRole Convert(UserRoleDto dto)
|
||||
{
|
||||
var entity = dto.Adapt<RelationUserUserRole>();
|
||||
return entity;
|
||||
}
|
||||
|
||||
protected virtual UserExtendedDto Convert(User entity)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user