You didn't say what contactRecords
and profile
exactly is, so it's hard to make sure how to solve the problem in best possible way, but following should do the trick:
var evaluatedVendors = contactRecords.Where(x => x.VendorId > 0)
.Select(x => new LandingPageVendorEvaluation()
{
ClientVendorId = x.ClientVendorId,
VendorId = x.VendorId,
VendorName = x.VendorName,
Outcome =
selectedCount > 0
? (x.VendorIsSelected ? OpportunityOutcomes.Win :
OpportunityOutcomes.Loss): OpportunityOutcomes.NoDecision,
Selected = x.VendorIsSelected,
IsClient = x.VendorIsClient,
IsOther = x.VendorIsOther
}).OrderBy(x => x.VendorName).Distinct();
var vendorIds = profile.EvaluatedVendors.Select(v => v.VendorId);
var itemsToAdd = evaluatedVendors.Where(v => !vendorIds.Contains(v.VendorId)).ToList();
profile.EvaluatedVendors.AddRange(itemsToAdd);
However, because you didn't specify what profile
is, it may not have AddRange
method. If that's the case you can iterate over itemsToAdd
instead and call Add
instead.