Merge pull request 'Фикс редактирования скважины' (#70) from feature/fix_well_update into dev

Reviewed-on: http://test.digitaldrilling.ru:8080/DDrilling/AsbCloudServer/pulls/70
This commit is contained in:
Никита Фролов 2023-07-04 16:42:14 +05:00
commit b8c9c37b49

View File

@ -173,16 +173,24 @@ namespace AsbCloudInfrastructure.Services
throw new ArgumentInvalidException("Текущее состояние работы скважины указано неправильно.", nameof(dto));
var oldRelations = (await GetCacheRelationCompanyWellAsync(token))
.Where(r => r.IdWell == dto.Id);
.Where(r => r.IdWell == dto.Id).ToArray();
if (dto.Companies.Count() != oldRelations.Count() ||
dto.Companies.Any(c => !oldRelations.Any(oldC => oldC.IdCompany == c.Id)))
if (dto.Companies.Count() != oldRelations.Length ||
dto.Companies.Any(c => oldRelations.All(oldC => oldC.IdCompany != c.Id)))
{
dbContext.RelationCompaniesWells
.RemoveRange(dbContext.RelationCompaniesWells
.Where(r => r.IdWell == dto.Id));
DropCacheRelationCompanyWell();
var newRelations = dto.Companies.Select(c => new RelationCompanyWell { IdWell = dto.Id, IdCompany = c.Id });
var newRelations = dto.Companies
.Select(c => new RelationCompanyWell
{
IdWell = dto.Id,
IdCompany = c.Id
});
dbContext.RelationCompaniesWells.AddRange(newRelations);
}