I have two lists: relatedContact
and fileContactIds
.
I am using the query to loop the relatedContacts list and return value of userClientCode (which I will make the image name) only if it is also in the fileContactIds
list. How can I put in a value (eg: "Default") if the value isn't in the second list ?
var result = relatedContact.SelectMany(rc => rc.contacts.Select(pc => new RelatedContactsDescription
{
imageUrl = mappedRelatedContactsPath + pc.userclientcode + ".jpg",
userclientcode = pc.userclientcode,
description = rc.clienttaxonomy,
fullname = pc.fullname,
email = pc.contactdetails != null && pc.contactdetails.Count >= 1 ? pc.contactdetails[0].contactdata : "",
address = pc.contactdetails != null && pc.contactdetails.Count >= 2 ? pc.contactdetails[1].contactdata : "",
phoneNumber = pc.contactdetails != null && pc.contactdetails.Count >= 3 ? pc.contactdetails[2].contactdata : "",
populated = string.IsNullOrEmpty(pc.userclientcode) ||
string.IsNullOrEmpty(pc.fullname) ||
string.IsNullOrEmpty(pc.contactdetails[0].contactdata) ? false : true,
}))
.Where(el => fileContactIds.Contains(el.userclientcode)).ToList();
I have read: Lambdas and Linq and Joins First or Default etc but all I can see is how to get matching data from both not also how to put a "fall-back" or default value if they don't match.
Thanks in advance