private static IEnumerable<TargetEvents> GetSubscriberTargetEvents(IEnumerable<string> subscriberTargetAudience, EventsCalendarEntity[] subscriberEvents)
        {
            foreach (var targetAudience in subscriberTargetAudience)
            {
                var targetEvents = subscriberEvents.Where(item => item.TargetAudience.Contains(targetAudience));
                if (!targetEvents.Any())
                    continue;

                var reportEventsEntry = new TargetEvents { Target = targetAudience, Events = targetEvents };
                yield return reportEventsEntry;
            }
        }
        private IEnumerable<EventsCalendarReport> GetEventsCalendarReport(SPWeb web, EventsCalendarEntity[] events, IEnumerable<EventsCalendarSubscriberEntity> subscribers, DateTime fromDate, DateTime toDate)
        {
            foreach (var subscriber in subscribers)
            {
                var subscriberEvents =
                    events.Where(item => item.TargetAudience.HasIntersections(subscriber.TargetAudience)).ToArray();
                if (!subscriberEvents.Any())
                    continue;

                var reportEvents = GetSubscriberTargetEvents(subscriber.TargetAudience, subscriberEvents);
                var subscriberReport = new EventsCalendarReport
                {
                    EmailTo = subscriber.Email,
                    FromDate = fromDate,
                    ToDate = toDate,
                    Events = reportEvents
                };

                yield return subscriberReport;
            }
        }
 private EventsCalendarEntity MapItemToEntity(SPListItem item)
 {
     var entity =
         new EventsCalendarEntity
             {
                 Id = item.ID,
                 Title = item.Title,
                 Category = item[EventsCalendarFields.Category] as string,
                 Description = item[EventsCalendarFields.Description] as string,
                 TargetAudience =
                     MapMultiChoiceValueToCollection(item[EventsCalendarFields.TargetAudience].ToString()).
                     ToArray(),
                 Location = item[EventsCalendarFields.Location] as string,
                 EventDate = (DateTime) item[EventsCalendarFields.EventDate],
                 Link =
                     item[EventsCalendarFields.Link] != null &&
                     !string.IsNullOrEmpty(item[EventsCalendarFields.Link].ToString())
                         ? new SPFieldUrlValue(item[EventsCalendarFields.Link].ToString()).Url
                         : string.Empty
             };
     return entity;
 }