예제 #1
0
        private void createSubscription(int subscriberId, int eventId, NotificationTypes nType)
        {

            EventType selectedEvent = new EventType() { ID = eventId };
            NotificationEndpoint notificationEP;
            Subscription subscription = new Subscription() { SubscriberID = subscriberId, EventType = selectedEvent };
            string emailEP;
            string smsEP;
            string webhookEP;

            if (nType == NotificationTypes.Email)
            {
                emailEP = txtBoxEmail.Text.Trim();
                bool emailCheck = IsValidEmail(emailEP);
                if (!emailCheck)
                {
                    MessageBox.Show("Invalid EmailID");
                }
                else
                {
                    if (string.Compare(emailEP, "") != 0)
                    {
                        notificationEP = new EmailNotificationSetting() { NotificationType = nType, EmailAddress = emailEP };
                        subscription.NotificationEndpoint = notificationEP;
                        SubscriptionBusiness.Subscribe(subscription);
                    }
                }
            }
            if (nType == NotificationTypes.SMS)
            {
                smsEP = txtBoxSMS.Text.Trim();
                bool phoneCheck = isValidPhoneNumber(smsEP);
                if (!phoneCheck)
                {
                    MessageBox.Show("Invalid Phone Number");
                }
                else
                {
                    if (string.Compare(smsEP, "") != 0)
                    {
                        notificationEP = new SmsNotificationSetting() { NotificationType = nType, PhoneNumber = smsEP };
                        subscription.NotificationEndpoint = notificationEP;
                        SubscriptionBusiness.Subscribe(subscription);
                    }
                }

            }
            if (nType == NotificationTypes.Webhook)
            {
                webhookEP = txtBoxWebhook.Text.Trim();
                bool webhookCheck = Uri.IsWellFormedUriString(webhookEP, UriKind.RelativeOrAbsolute);
                bool webhookhttp = IsValidUrl(webhookEP);
                if (!webhookCheck || webhookhttp == false)
                {
                    MessageBox.Show("Invalid URL");
                }
                else
                {
                    if (string.Compare(webhookEP, "") != 0)
                    {
                        notificationEP = new WebhookNotificationSetting() { NotificationType = nType, Url = webhookEP };
                        subscription.NotificationEndpoint = notificationEP;
                        SubscriptionBusiness.Subscribe(subscription);
                    }
                }

            }
        }
        /// <summary>
        /// The GetNotification method gets the notification
        /// </summary>
        /// <param name="notificationType">The notificationType parameter</param>
        /// <param name="connectionString">The connectionString parameter</param>
        /// <param name="subscriptionId">The subscriptionId parameter</param>
        /// <returns>returns the notification endpoint object</returns>        
        public NotificationEndpoint GetNotification(string notificationType, string connectionString, int subscriptionId)
        {
            NotificationEndpoint newNotification = new NotificationEndpoint();

            List<DbParameter> parameters = new List<DbParameter>();
            parameters.Add(new IntParameter("subscriptionId", subscriptionId));

            if (string.Compare(notificationType, "Email") == 0)
            {
                EmailNotificationSetting emailNotification = new EmailNotificationSetting() { NotificationType = AuthNet.PoC.EventModel.Entities.NotificationTypes.Email };
                using (IDataReader reader = ExecuteStoredProcReader("GetEmailNotificationSetting", parameters))
                {
                    while (reader.Read())
                    {
                        emailNotification.EmailAddress = reader[2].ToString();
                    }
                }

                newNotification = emailNotification;
            }
            else if (string.Compare(notificationType, "SMS") == 0)
            {
                SmsNotificationSetting smsNotification = new SmsNotificationSetting() { NotificationType = NotificationTypes.SMS };
                using (IDataReader reader = ExecuteStoredProcReader("GetSmsNotificationSetting", parameters))
                {
                    while (reader.Read())
                    {
                        smsNotification.PhoneNumber = reader[2].ToString();
                    }
                }

                newNotification = smsNotification;
            }
            else if (string.Compare(notificationType, "Webhook") == 0)
            {
                WebhookNotificationSetting webhookNotification = new WebhookNotificationSetting() { NotificationType = NotificationTypes.Webhook };
                using (IDataReader reader = ExecuteStoredProcReader("GetWebhookNotificationSetting", parameters))
                {
                    while (reader.Read())
                    {
                        webhookNotification.Url = reader[2].ToString();
                    }
                }

                newNotification = webhookNotification;
            }

            return newNotification;
        }