public PrntKaskoAdditionalAgreementViewModel GetKaskoModificationAdditionalAgreementViewModel(Basket basket)
{
var agreement = new PrntKaskoAdditionalAgreementViewModel();
var deal = basket.GetKaskoDeal();
var auto = deal.GetAuto();
var drivers = deal.AutoDeal.Drivers;
var insurant = deal.GetInsurantPerson();
var tsIdentityCard = deal.AutoDeal.TsIdentityCard;
var modifications = _queryService.GetByExpression<KaskoModificationsInBasket>(
x => x.Where(m => m.BasketNumber == basket.Number));
var agreements = _queryService.GetByExpression<KaskoModificationsAgreementsInBasket>(
x => x.Where(m => m.BasketNumber == basket.Number));
var needToPrintRiskDegreeChangeAgreement = modifications.Any(x => _riskDegreeChanges.Contains(x.ModificationListForKaskoCode));
var needToPrintDriversListChangeAgreement = modifications.Any(x => _driversListChanges.Contains(x.ModificationListForKaskoCode));
var needToPrintAutoRegistrationChangeAgreement = modifications.Any(x => _autoRegistrationChanges.Contains(x.ModificationListForKaskoCode));
var needToPrintAutoStartChangeAgreement = modifications.Any(x => _autoStartChanges.Contains(x.ModificationListForKaskoCode));
var needToPrintInformationChangeAgreement = modifications.Any(x => _informationChanges.Contains(x.ModificationListForKaskoCode));
agreement = new PrntKaskoAdditionalAgreementViewModel
{
IsPreview = !_notPreviewStatusTypes.Contains(deal.DealStatusCode),
IsMultidrive = deal.AutoDeal.IsMultidrive,
PolicyNumber = deal.PolicyNumber,
PolicyDate = deal.DateStart.Value,
ChangesStartDate = deal.ChangesStartDate.Value,
RiskDegreeChangeAgreement = new PrntChangeAgreementViewModel
{
IsVisible = needToPrintRiskDegreeChangeAgreement,
Number = needToPrintRiskDegreeChangeAgreement ? GetAgreementNumber(agreements, ModificationAgreementNames.RiskDegreeChangeAgreement) : null
},
DriversListChangeAgreement = new PrntChangeAgreementViewModel
{
IsVisible = needToPrintDriversListChangeAgreement,
Number = needToPrintDriversListChangeAgreement ? GetAgreementNumber(agreements, ModificationAgreementNames.DriversListChangeAgreement) : null
},
AutoRegistrationChangeAgreement = new PrntChangeAgreementViewModel
{
IsVisible = modifications.Any(x => _autoRegistrationChanges.Contains(x.ModificationListForKaskoCode)),
Number = needToPrintAutoRegistrationChangeAgreement ? GetAgreementNumber(agreements, ModificationAgreementNames.AutoRegistrationChangeAgreement) : null
},
AutoStartChangeAgreement = new PrntChangeAgreementViewModel
{
IsVisible = modifications.Any(x => _autoStartChanges.Contains(x.ModificationListForKaskoCode)),
Number = needToPrintAutoStartChangeAgreement ? GetAgreementNumber(agreements, ModificationAgreementNames.AutoStartChangeAgreement) : null
},
InformationChangeAgreement = new PrntChangeAgreementViewModel
{
IsVisible = modifications.Any(x => _informationChanges.Contains(x.ModificationListForKaskoCode)),
Number = needToPrintInformationChangeAgreement ? GetAgreementNumber(agreements, ModificationAgreementNames.InformationChangeAgreement) : null
},
Auto = new PrntAutoViewModel
{
RegNumber = auto.RegistrationNumber,
OriginalKeysAmount = auto.OriginalKeysAmount.ToString(),
},
Insurant = new PrntInsurantViewModel
{
LastName = insurant.LastName,
Name = insurant.Name,
MiddleName = insurant.MiddleName
},
TsIdentityCard = new PrntTsIdentityCardViewModel
{
CardTypeShortName = tsIdentityCard.TsIdentityCardType.Name,
Series = tsIdentityCard.Series,
Number = tsIdentityCard.Number,
DateOfIssued = tsIdentityCard.DateOfIssued.GetValueOrDefault()
},
Drivers = drivers.Select(d => new PrntKaskoAdditionalAgreementDriverViewModel
{
FullName = d.Subject.IndividualEntity.Person.GetFullName(),
DateOfBirth = d.Subject.IndividualEntity.Person.DateOfBirth.ToString(),
DrivingExperienceDateStart = d.DrivingExperiences.Last()?.DrivingExperienceDateStart.ToString(),
SexCode = d.Subject.IndividualEntity.Person.SexCode,
IsMaried = d.Subject.IndividualEntity.Person.IsMaried,
HasChildren = d.Subject.IndividualEntity.Person.HasChildren,
}).ToList(),
Modifications = modifications.Where(x => _informationChanges.Contains(x.ModificationListForKaskoCode)).Select(m => new PrntModificationViewModel
{
ChangeName = m.ChangeName,
NewValue = GetNewValue(deal, m)
}).ToList()
};
return agreement;
}
У меня сейчас изменения по водителям выводится не корректно:
Стороны пришли к соглашению считать верным по Договору страхования:
В разделе ФИО водителя: Бульбар Анастасияа Геннадьевнаа, Лобачевс Викторр Викторовичч, Бульбаа
Екатеринаа Олеговнаа
В разделе ФИО водителя: Бульбар Анастасияа Геннадьевнаа, Лобачевс Викторр Викторовичч, Бульбаа
Екатеринаа Олеговнаа
В разделе ФИО водителя: Бульбар Анастасияа Геннадьевнаа, Лобачевс Викторр Викторовичч, Бульбаа
Екатеринаа Олеговнаа
Надо что бы либо была только одна строка с измененными фио через запятую, либо в каждой новой строке была только одно фио
The issue arises because your code is adding multiple entries to the Modifications list for each driver name change, and each entry includes all driver names, leading to duplicates in the output. To resolve this, you need to group the modifications by their type and change path before creating the PrntModificationViewModel instances. This way, you'll have only one entry per type of modification, preventing duplicate entries when multiple modifications of the same type exist.
Here's how you can modify your code:
In your GetKaskoModificationAdditionalAgreementViewModel method, replace the part where you create the Modifications list with the following code:
csharp
// Group modifications by ModificationListForKaskoCode and ChangePath
var groupedModifications = modifications
.Where(x => _informationChanges.Contains(x.ModificationListForKaskoCode))
.GroupBy(m => new { m.ModificationListForKaskoCode, m.ChangePath })
.Select(g => new PrntModificationViewModel
{
ChangeName = g.First().ChangeName,
NewValue = GetNewValue(deal, g.First())
})
.ToList();
agreement.Modifications = groupedModifications;
This code groups the modifications by their ModificationListForKaskoCode and ChangePath, ensuring that you only create one PrntModificationViewModel per group of similar modifications. This effectively removes duplicates from the modifications list.
Here's the complete adjusted method for clarity:
csharp
public PrntKaskoAdditionalAgreementViewModel GetKaskoModificationAdditionalAgreementViewModel(Basket basket)
{
var agreement = new PrntKaskoAdditionalAgreementViewModel();
var deal = basket.GetKaskoDeal();
var auto = deal.GetAuto();
var drivers = deal.AutoDeal.Drivers;
var insurant = deal.GetInsurantPerson();
var tsIdentityCard = deal.AutoDeal.TsIdentityCard;
var modifications = _queryService.GetByExpression<KaskoModificationsInBasket>(
x => x.Where(m => m.BasketNumber == basket.Number));
var agreements = _queryService.GetByExpression<KaskoModificationsAgreementsInBasket>(
x => x.Where(m => m.BasketNumber == basket.Number));
var needToPrintRiskDegreeChangeAgreement = modifications.Any(x => _riskDegreeChanges.Contains(x.ModificationListForKaskoCode));
var needToPrintDriversListChangeAgreement = modifications.Any(x => _driversListChanges.Contains(x.ModificationListForKaskoCode));
var needToPrintAutoRegistrationChangeAgreement = modifications.Any(x => _autoRegistrationChanges.Contains(x.ModificationListForKaskoCode));
var needToPrintAutoStartChangeAgreement = modifications.Any(x => _autoStartChanges.Contains(x.ModificationListForKaskoCode));
var needToPrintInformationChangeAgreement = modifications.Any(x => _informationChanges.Contains(x.ModificationListForKaskoCode));
agreement = new PrntKaskoAdditionalAgreementViewModel
{
IsPreview = !_notPreviewStatusTypes.Contains(deal.DealStatusCode),
IsMultidrive = deal.AutoDeal.IsMultidrive,
PolicyNumber = deal.PolicyNumber,
PolicyDate = deal.DateStart.Value,
ChangesStartDate = deal.ChangesStartDate.Value,
RiskDegreeChangeAgreement = new PrntChangeAgreementViewModel
{
IsVisible = needToPrintRiskDegreeChangeAgreement,
Number = needToPrintRiskDegreeChangeAgreement ? GetAgreementNumber(agreements, ModificationAgreementNames.RiskDegreeChangeAgreement) : null
},
DriversListChangeAgreement = new PrntChangeAgreementViewModel
{
IsVisible = needToPrintDriversListChangeAgreement,
Number = needToPrintDriversListChangeAgreement ? GetAgreementNumber(agreements, ModificationAgreementNames.DriversListChangeAgreement) : null
},
AutoRegistrationChangeAgreement = new PrntChangeAgreementViewModel
{
IsVisible = modifications.Any(x => _autoRegistrationChanges.Contains(x.ModificationListForKaskoCode)),
Number = needToPrintAutoRegistrationChangeAgreement ? GetAgreementNumber(agreements, ModificationAgreementNames.AutoRegistrationChangeAgreement) : null
},
AutoStartChangeAgreement = new PrntChangeAgreementViewModel
{
IsVisible = modifications.Any(x => _autoStartChanges.Contains(x.ModificationListForKaskoCode)),
Number = needToPrintAutoStartChangeAgreement ? GetAgreementNumber(agreements, ModificationAgreementNames.AutoStartChangeAgreement) : null
},
InformationChangeAgreement = new PrntChangeAgreementViewModel
{
IsVisible = modifications.Any(x => _informationChanges.Contains(x.ModificationListForKaskoCode)),
Number = needToPrintInformationChangeAgreement ? GetAgreementNumber(agreements, ModificationAgreementNames.InformationChangeAgreement) : null
},
Auto = new PrntAutoViewModel
{
RegNumber = auto.RegistrationNumber,
OriginalKeysAmount = auto.OriginalKeysAmount.ToString(),
},
Insurant = new PrntInsurantViewModel
{
LastName = insurant.LastName,
Name = insurant.Name,
MiddleName = insurant.MiddleName
},
TsIdentityCard = new PrntTsIdentityCardViewModel
{
CardTypeShortName = tsIdentityCard.TsIdentityCardType.Name,
Series = tsIdentityCard.Series,
Number = tsIdentityCard.Number,
DateOfIssued = tsIdentityCard.DateOfIssued.GetValueOrDefault()
},
Drivers = drivers.Select(d => new PrntKaskoAdditionalAgreementDriverViewModel
{
FullName = d.Subject.IndividualEntity.Person.GetFullName(),
DateOfBirth = d.Subject.IndividualEntity.Person.DateOfBirth.ToString(),
DrivingExperienceDateStart = d.DrivingExperiences.Last()?.DrivingExperienceDateStart.ToString(),
SexCode = d.Subject.IndividualEntity.Person.SexCode,
IsMaried = d.Subject.IndividualEntity.Person.IsMaried,
HasChildren = d.Subject.IndividualEntity.Person.HasChildren,
}).ToList(),
// Here is the modified part
Modifications = modifications
.Where(x => _informationChanges.Contains(x.ModificationListForKaskoCode))
.GroupBy(m => new { m.ModificationListForKaskoCode, m.ChangePath })
.Select(g => new PrntModificationViewModel
{
ChangeName = g.First().ChangeName,
NewValue = GetNewValue(deal, g.First())
})
.ToList()
};
return agreement;
}
By grouping the modifications, you ensure that each type of modification is represented only once in the output. This will either display a single line with the changed driver names separated by commas or, if you adjust the GetNewValue method to handle individual driver modifications (assuming you have access to the specific driver data), display each driver's name on a separate line.
This change will fix the issue you're experiencing, and your output should now correctly display the driver changes without unnecessary duplication.