Пример #1
0
        /// <summary>
        /// Send Notification and reference subscribers.
        /// </summary>
        /// <param name="notification">The Notification data</param>
        /// <param name="subscribers">The Subscribers</param>
        /// <returns>Whether the command is succeeded</returns>
        public static SendNotificationResult SendNotification(Notification notification, ref List <Account> subscribers)
        {
            subscribers.Clear();

            try
            {
                SqlConnection connection = DBConnect.GetConnection();
                connection.Open();

                SqlCommand command = new SqlCommand();
                command.Connection = connection;

                // select all subscribers that role is Role.Subscriber
                AccountDB.GetSubscribers(command, notification.Location, ref subscribers);
                if (subscribers.Count == 0)
                {
                    connection.Close();
                    connection.Dispose();
                    command.Dispose();

                    return(SendNotificationResult.NoSubscribers);
                }
                // insert Notification and get the new notificationId
                int notificationId = InsertNotification(command, notification);
                notification.NotificationId = notificationId;
                // insert SubscriberNotification map table
                InsertSubscriberNotification(command, notificationId, ref subscribers);

                connection.Close();
                connection.Dispose();
                command.Dispose();

                return(SendNotificationResult.Succeeded);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return(SendNotificationResult.DatabaseError);
            }
        }