diff --git a/AsbCloudInfrastructure/Services/WellService.cs b/AsbCloudInfrastructure/Services/WellService.cs index d55bd2a5..6d70dd9c 100644 --- a/AsbCloudInfrastructure/Services/WellService.cs +++ b/AsbCloudInfrastructure/Services/WellService.cs @@ -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); }