|
@@ -45,6 +45,12 @@ public class SnapshotUserApplication : ISnapshotUserApplication, IScopeDependenc
|
|
|
Id = dto.SafetyTypeId,
|
|
|
Citizens = []
|
|
|
};
|
|
|
+ var citizenExists = await _citizenRepository.Queryable()
|
|
|
+ .LeftJoin<CitizenRelationSafetyType>((citizen, relation) => citizen.Id == relation.CitizenId)
|
|
|
+ .Where((citizen, relation) => dto.CitizenIds.Contains(citizen.Id) && relation.SafetyTypeId == dto.SafetyTypeId)
|
|
|
+ .Select((citizen, relation) => citizen.Id)
|
|
|
+ .ToListAsync(token);
|
|
|
+ dto.CitizenIds = dto.CitizenIds.Except(citizenExists).ToList();
|
|
|
foreach (var item in dto.CitizenIds)
|
|
|
{
|
|
|
safeType.Citizens.Add(new Citizen { Id = item });
|
|
@@ -54,7 +60,6 @@ public class SnapshotUserApplication : ISnapshotUserApplication, IScopeDependenc
|
|
|
.Include(m => m.Citizens, new InsertNavOptions()
|
|
|
{
|
|
|
ManyToManyNoDeleteMap = true
|
|
|
-
|
|
|
})
|
|
|
.ExecuteCommandAsync();
|
|
|
}
|
|
@@ -101,8 +106,10 @@ public class SnapshotUserApplication : ISnapshotUserApplication, IScopeDependenc
|
|
|
{
|
|
|
var query = _citizenRepository.Queryable(includeDeleted: true)
|
|
|
.LeftJoin<ThirdAccount>((citizen, third) => citizen.Id == third.ExternalId)
|
|
|
+ .LeftJoin<CitizenRelationSafetyType>((citizen, third, relation) => relation.CitizenId == citizen.Id)
|
|
|
.WhereIF(dto.PhoneNumber.NotNullOrEmpty(), (citizen, third) => citizen.PhoneNumber.Contains(dto.PhoneNumber))
|
|
|
- .Select((citizen, third) => new GetThirdCitizenOutDto { CitizenId = citizen.Id}, true);
|
|
|
+ .Where((citizen, third, relation) => relation.SafetyTypeId == dto.SafteyTypeId && relation.CitizenId == null)
|
|
|
+ .Select((citizen, third, relation) => new GetThirdCitizenOutDto { CitizenId = citizen.Id}, true);
|
|
|
#if DEBUG
|
|
|
var sql = query.ToSqlString();
|
|
|
#endif
|