Merge pull request 'Рефакторинг базового репозитория. Фикс обновления ГГД' (#267) from feature/refactoring_repository_base into dev

Reviewed-on: http://test.digitaldrilling.ru:8080/DDrilling/AsbCloudServer/pulls/267
This commit is contained in:
Никита Фролов 2024-04-23 11:49:00 +05:00
commit 87d03e5621
2 changed files with 11 additions and 6 deletions

View File

@ -133,18 +133,22 @@ namespace AsbCloudInfrastructure.Repository
if (ids.Length != dtos.Count())
throw new ArgumentInvalidException(nameof(dtos), "Все записи должны иметь уникальные Id");
var dbSet = dbContext.Set<TEntity>();
var existingEntitiesCount = await dbSet
var existingEntitiesCount = await dbContext.Set<TEntity>()
.Where(o => ids.Contains(o.Id))
.CountAsync(token);
if (ids.Length != existingEntitiesCount)
throw new ArgumentInvalidException(nameof(dtos), "Все записи должны существовать в БД");
var entities = dtos.Select(Convert);
var entities = dbContext.Set<TEntity>().Where(e => ids.Contains(e.Id));
dbContext.Set<TEntity>().UpdateRange(entities);
return await dbContext.SaveChangesAsync(token);
var entries = entities.Select(entity => dbContext.Set<TEntity>().Update(entity)).ToList();
var affected = await dbContext.SaveChangesAsync(token);
entries.ForEach(entry => entry.State = EntityState.Detached);
return affected;
}
/// <inheritdoc/>

View File

@ -274,6 +274,7 @@ namespace AsbCloudInfrastructure.Services
dto.Timezone = GetTimezone(entity.Id);
dto.StartDate = dbContext.WellOperations.Where(e => e.IdType == WellOperation.IdOperationTypeFact)
.AsNoTracking()
.MinOrDefault(e => e.DateStart)?.ToRemoteDateTime(dto.Timezone.Hours);
dto.WellType = entity.WellType.Caption;
dto.Cluster = entity.Cluster.Caption;