private bool promoInd = false; //Check for (promo may only appear once in a list) public void ReadJsonFile() { _jsonText = File.ReadAllText(FilePath); RecipientItemList = JsonConvert.DeserializeObject <Recepient.RecipientsItemList>(_jsonText); for (int i = 0; i < RecipientItemList.recipients.Count; i++) { _recepient1 = RecipientItemList.recipients[i]; _itemListName1 = _recepient1.name; for (int j = 0; j < RecipientItemList.recipients.Count; j++) { _recepient2 = RecipientItemList.recipients[j]; _itemListName2 = _recepient2.name; if (_itemListName1 != _itemListName2 && !recepientsSelected.Contains(_itemListName1)) //Each pair of names should only appear once in the list, the order does not matter. { if (promoInd == true) //Check for (promo may only appear once in a list) { if (GetIndexOfItemTags(_recepient1, "promo") > -1) { RemoveItemTagsByIndex(_recepient1, GetIndexOfItemTags(_recepient1, "promo")); } if (GetIndexOfItemTags(_recepient2, "promo") > -1) { RemoveItemTagsByIndex(_recepient2, GetIndexOfItemTags(_recepient2, "promo")); } } if (_recepient1.tags.Intersect(_recepient2.tags).Count() >= 2) //a list of each pair of names which have 2 or more tags in common { if (GetIndexOfItemTags(_recepient1, "promo") > -1 || GetIndexOfItemTags(_recepient2, "promo") > -1) { promoInd = true; } ConCatRecepientsSelected(_itemListName1, _itemListName2); break; } } } } }
private void RemoveItemTagsByIndex(Recepient.Recipients recepientItem, int index) { recepientItem.tags.RemoveAt(index); }
private int GetIndexOfItemTags(Recepient.Recipients recepientItem, string Item) { return(recepientItem.tags.IndexOf(Item)); }