Beispiel #1
0
        /// <summary>
        /// Patches a sms contact point with a subscription to a topic. Will create a new sms contact point if the sms contact point does not exist. Cannot be used to mark a sms contact point as inactive.
        /// </summary>
        /// <param name="phoneNumber">The phone number of the sms contact point eg. +1234567890</param>
        /// <param name="countryName">the country of the sms contact point</param>
        /// <param name="topicId">the identifier of the topic</param>
        /// <param name="state">The state the subscription should be in eg. OptInExplicit</param>
        /// <returns></returns>
        private static async Task PatchSmsContactPoint(string phoneNumber, string countryName, Guid topicId, ContactPointTopicSettingState state)
        {
            SmsContactPoint smsContactPoint = new SmsContactPoint()
            {
                Phone   = phoneNumber,
                Country = countryName
            };

            smsContactPoint.TopicSettings.Add(new ContactPointTopicSetting
            {
                TopicId           = topicId,
                CultureName       = CultureInfo.CurrentCulture.ToString(),
                LastSourceSetDate = DateTime.UtcNow,
                OriginalSource    = "SampleCPMProject",
                State             = state
            });
            using (HttpClient client = await CPMClientGenerator.CreateHttpClientAsync())
            {
                HttpResponseMessage response = await client.PatchAsync("api/SmsContacts", smsContactPoint);

                if (response.IsSuccessStatusCode)
                {
                    SmsContactPoint patched = await response.Content.ReadAsAsync <SmsContactPoint>();

                    Console.WriteLine(JsonConvert.SerializeObject(patched, Formatting.Indented));
                }
                else
                {
                    Console.WriteLine(await response.Content.ReadAsStringAsync());
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Patches a phone contact point with a subscription to a topic. Will create a new phone contact point if the phone contact point does not exist. Cannot be used to mark a phone contact point as inactive.
        /// </summary>
        /// <param name="phoneNumber">The phone number of the phone contact point eg. +1234567890</param>
        /// <param name="firstName">Optional, First Name. </param>
        /// <param name="middleName">Optional, Middle Name".</param>
        /// <param name="lastName">Optional, Last Name".</param>
        /// <param name="generationalSuffix">Optional, suffix eg. Sr".</param>
        /// <param name="countryName">the country of the phone contact point</param>
        /// <param name="topicId">the identifier of the topic</param>
        /// <param name="state">The state the subscription should be in eg. OptInExplicit</param>
        /// <returns></returns>
        private static async Task PatchPhoneContactPoint(string phoneNumber, string firstName, string middleName, string lastName, string generationalSuffix, string countryName, Guid topicId, ContactPointTopicSettingState state)
        {
            ContactName name = new ContactName()
            {
                FirstName          = firstName,
                MiddleName         = middleName,
                LastName           = lastName,
                GenerationalSuffix = generationalSuffix
            };

            PhoneContactIdentity identity = new PhoneContactIdentity()
            {
                PhoneNumber = phoneNumber,
                Name        = name
            };

            PhoneContactPoint phoneContactPoint = new PhoneContactPoint()
            {
                Identity = identity,
                Country  = countryName
            };

            phoneContactPoint.TopicSettings.Add(new ContactPointTopicSetting
            {
                TopicId           = topicId,
                CultureName       = CultureInfo.CurrentCulture.ToString(),
                LastSourceSetDate = DateTime.UtcNow,
                OriginalSource    = "SampleCPMProject",
                State             = state
            });
            using (HttpClient client = await CPMClientGenerator.CreateHttpClientAsync())
            {
                HttpResponseMessage response = await client.PatchAsync("api/PhoneContacts", phoneContactPoint);

                if (response.IsSuccessStatusCode)
                {
                    // By design, we do not return the request body after a successful phone contact point patch
                }
                else
                {
                    Console.WriteLine(await response.Content.ReadAsStringAsync());
                }
            }
        }