доработка методов репозитория

This commit is contained in:
eugeniy_ivanov 2023-02-13 23:11:39 +05:00
parent 95790af1f6
commit 6bf992f1f6
2 changed files with 13 additions and 17 deletions

View File

@ -72,6 +72,5 @@ namespace AsbCloudDb.Model
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;
}
}

View File

@ -122,7 +122,6 @@ namespace AsbCloudInfrastructure.Repository
entity.Position = user.Position;
entity.IdCompany = user.IdCompany;
entity.IdState = user.IdState;
entity.RelationUsersUserRoles = user.RelationUsersUserRoles;
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)
{