private void CreateMarketingList()
        {
            Console.WriteLine("=== Creating the Marketing List ===");
            // Create the marketing list.  Make it static because members are going to be
            // added to the list.
            var list = new List
            {
                CreatedFromCode = new OptionSetValue((int)ListCreatedFromCode.Contact),
                ListName = "Sample Contact Marketing List",
                Type = MarketingListType.Static
            };
            
            _marketingListId = _serviceProxy.Create(list);

            NotifyEntityCreated(List.EntityLogicalName, _marketingListId);

            //<snippetDistributeCampaignFromMarketingList6>
            // Add a list of contacts to the marketing list.
            var addMemberListReq = new AddListMembersListRequest
            {
                MemberIds = new[] { _contactIdList[0], _contactIdList[2] },
                ListId = _marketingListId
            };

            _serviceProxy.Execute(addMemberListReq);

            Console.WriteLine("  Contacts with GUIDs \r\n\t{{{0}}}\r\n\tand {{{1}}}\r\n  were added to the list.",
                _contactIdList[0], _contactIdList[1]);
            //</snippetDistributeCampaignFromMarketingList6>

            //<snippetDistributeCampaignFromMarketingList7>
            // Copy the marketing list.  First create a new one, and then copy over the
            // members.
            list.ListName = list.ListName + " Copy";
            _copiedMarketingListId = _serviceProxy.Create(list);
            var copyRequest = new CopyMembersListRequest
            {
                SourceListId = _marketingListId,
                TargetListId = _copiedMarketingListId
            };

            _serviceProxy.Execute(copyRequest);
            //</snippetDistributeCampaignFromMarketingList7>

            //<snippetDistributeCampaignFromMarketingList8>
            // Add a single contact to the copied marketing list.
            var addMemberReq = new AddMemberListRequest
            {
                EntityId = _contactIdList[1],
                ListId = _copiedMarketingListId
            };

            _serviceProxy.Execute(addMemberReq);

            Console.WriteLine("  Contact with GUID\r\n\t{{{0}}}\r\n  was added to the list.",
                _contactIdList[1]);
            //</snippetDistributeCampaignFromMarketingList8>

            //<snippetDistributeCampaignFromMarketingList9>
            // Qualify the marketing list.
            var qualifyRequest = new QualifyMemberListRequest
            {
                OverrideorRemove = OverrideOrRemove.Override,
                MembersId = new[] { _contactIdList[0], _contactIdList[1] },
                ListId = _copiedMarketingListId
            };

            _serviceProxy.Execute(qualifyRequest);

            Console.WriteLine("  Qualified the copied marketing list so that it only\r\n    includes the first two members.");
            //</snippetDistributeCampaignFromMarketingList9>
        }
Esempio n. 2
0
        private void CreateMarketingList()
        {
            Console.WriteLine("=== Creating the Marketing List ===");
            // Create the marketing list.  Make it static because members are going to be
            // added to the list.
            var list = new List
            {
                CreatedFromCode = new OptionSetValue((int)ListCreatedFromCode.Contact),
                ListName        = "Sample Contact Marketing List",
                Type            = MarketingListType.Static
            };

            _marketingListId = _serviceProxy.Create(list);

            NotifyEntityCreated(List.EntityLogicalName, _marketingListId);

            //<snippetDistributeCampaignFromMarketingList6>
            // Add a list of contacts to the marketing list.
            var addMemberListReq = new AddListMembersListRequest
            {
                MemberIds = new[] { _contactIdList[0], _contactIdList[2] },
                ListId    = _marketingListId
            };

            _serviceProxy.Execute(addMemberListReq);

            Console.WriteLine("  Contacts with GUIDs \r\n\t{{{0}}}\r\n\tand {{{1}}}\r\n  were added to the list.",
                              _contactIdList[0], _contactIdList[1]);
            //</snippetDistributeCampaignFromMarketingList6>

            //<snippetDistributeCampaignFromMarketingList7>
            // Copy the marketing list.  First create a new one, and then copy over the
            // members.
            list.ListName          = list.ListName + " Copy";
            _copiedMarketingListId = _serviceProxy.Create(list);
            var copyRequest = new CopyMembersListRequest
            {
                SourceListId = _marketingListId,
                TargetListId = _copiedMarketingListId
            };

            _serviceProxy.Execute(copyRequest);
            //</snippetDistributeCampaignFromMarketingList7>

            //<snippetDistributeCampaignFromMarketingList8>
            // Add a single contact to the copied marketing list.
            var addMemberReq = new AddMemberListRequest
            {
                EntityId = _contactIdList[1],
                ListId   = _copiedMarketingListId
            };

            _serviceProxy.Execute(addMemberReq);

            Console.WriteLine("  Contact with GUID\r\n\t{{{0}}}\r\n  was added to the list.",
                              _contactIdList[1]);
            //</snippetDistributeCampaignFromMarketingList8>

            //<snippetDistributeCampaignFromMarketingList9>
            // Qualify the marketing list.
            var qualifyRequest = new QualifyMemberListRequest
            {
                OverrideorRemove = OverrideOrRemove.Override,
                MembersId        = new[] { _contactIdList[0], _contactIdList[1] },
                ListId           = _copiedMarketingListId
            };

            _serviceProxy.Execute(qualifyRequest);

            Console.WriteLine("  Qualified the copied marketing list so that it only\r\n    includes the first two members.");
            //</snippetDistributeCampaignFromMarketingList9>
        }