I have a Foreach loop and every iteration puts the record into a system. Then I also have a foreach loop that gets the data from a linqQuery. I want to iterate through each one and compare the FullName of each and if its true it makes a bool as true and if not it marks it as false. How would I go about doing that. This is what I have so far.
foreach (Lead p in sessionleads)
{
string AccountName = "";
string AccountId = "";
string ContactId = "";
bool b = false;
foreach (var a in linqQuery)
{
AccountName = a.AccountName.ToString();
AccountId = a.AccountId.ToString();
ContactId = a.ContactId.ToString();
if (AccountName.ToString() == p.AccountName.ToString())
{
b = true;
}
else
{
b = false;
}
}
if (b == true)
{
Entity opportunity = new Entity("opportunity");
opportunity["new_contact"] = new EntityReference("contact", new Guid(ContactId));
opportunity["customerid"] = new EntityReference("account", new Guid(AccountId));
opportunity.FormattedValues["new_leadstatus"] = p.Status;
opportunity.FormattedValues["statuscode"] = p.Type;
//opportunity["ownerid"] =
Guid opportunityId = orgService.Create(opportunity);
}
else
{
Entity opportunity = new Entity("opportunity");
opportunity["new_contact"] = new EntityReference("contact", contactId);
opportunity["customerid"] = new EntityReference("account", accountId);
opportunity.FormattedValues["new_leadstatus"] = p.Status;
opportunity.FormattedValues["statuscode"] = p.Type;
//opportunity["ownerid"] =
Guid opportunityId = orgService.Create(opportunity);
}
}
Thanks!
Add a break after the first check:
Even better:
Then, the use that to do the rest of the logic checks.