Exemplo n.º 1
0
        /// <summary>
        ///     Gets all subscribed people for a certain newsletter.
        /// </summary>
        /// <param name="ReportId">The Report Id.</param>
        /// <returns>An int array of PersonId.</returns>
        public int[] GetSubscribersForNewsletterFeed(int newsletterFeedId)
        {
            Dictionary <int, bool> hash = new Dictionary <int, bool>();

            // First, we get the newsletter feed we're working with.

            BasicNewsletterFeed newsletterFeed = GetNewsletterFeed(newsletterFeedId);

            if (newsletterFeed.DefaultSubscribed)
            {
                // Since the default is to subscribe to this report for this organization, we
                // must first get all the PersonIds that are members of the associated org, and
                // set their subscription to true. We will later follow up with the individual
                // overrides to get the final list.

                // Note that the individual preferences may have people not in the organization,
                // and so the final list may include subscribers that are nonmembers.

                BasicOrganization[] orgTree = GetOrganizationTree(newsletterFeed.OrganizationId);

                List <int> organizationIds = new List <int>();

                foreach (BasicOrganization org in orgTree)
                {
                    organizationIds.Add(org.Identity);
                }

                int[] personIds = GetMembersForOrganizations(organizationIds.ToArray());

                foreach (int personId in personIds)
                {
                    hash[personId] = true;
                }
            }

            // Now, go over each individual preference for this newsletter.

            using (DbConnection connection = GetMySqlDbConnection())
            {
                connection.Open();

                DbCommand command =
                    GetDbCommand(
                        "SELECT PersonId,Subscribed FROM NewsletterSubscriptions WHERE NewsletterFeedId=" +
                        newsletterFeedId.ToString(), connection);

                using (DbDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        int  personId   = reader.GetInt32(0);
                        bool subscribed = reader.GetBoolean(1);

                        if (personId > 0)
                        {
                            hash[personId] = subscribed;
                        }
                    }
                }
            }

            // Finally, assemble the result. We have a hash table where all the ints that are true should
            // go into the final result.

            List <int> result = new List <int>();

            foreach (int key in hash.Keys)
            {
                if (hash[key])
                {
                    result.Add(key);
                }
            }

            return(result.ToArray());
        }
Exemplo n.º 2
0
 public static NewsletterFeed FromBasic(BasicNewsletterFeed basic)
 {
     return(new NewsletterFeed(basic));
 }
Exemplo n.º 3
0
 public BasicNewsletterFeed(BasicNewsletterFeed original)
     : this(original.NewsletterFeedId, original.OrganizationId, original.DefaultSubscribed, original.Name)
 {
 }
Exemplo n.º 4
0
 private NewsletterFeed(BasicNewsletterFeed basic)
     : base(basic)
 {
 }