Ejemplo n.º 1
0
        public void ManageLists(XrmServiceContext context, Contact contact)
        {
            foreach (RepeaterItem item in MarketingList.Items)
            {
                if (item != null)
                {
                    RepeaterItem repeaterItem = item;

                    var ml = context.ListSet.First(m => m.ListId == new Guid(((HiddenField)(repeaterItem.FindControl("ListID"))).Value));

                    var listCheckBox = (CheckBox)item.FindControl("ListCheckbox");

                    var contactLists = contact.listcontact_association.ToList();

                    var inList = contactLists.Any(list => list.ListId == ml.ListId);

                    if (listCheckBox.Checked && !inList)
                    {
                        context.AddMemberList(ml.ListId.Value, contact.ContactId.Value);
                    }
                    else if (!listCheckBox.Checked && inList)
                    {
                        context.RemoveMemberList(ml.ListId.Value, contact.ContactId.Value);
                    }
                }
            }
        }