public EventOccurrenceAttendee(EventOccurrence eventOccurrence, EventRegistration eventRegistration, EventAttendee attendee)
 {
     if (eventOccurrence == null)
         throw new ArgumentNullException("eventOccurrence");
     if (eventRegistration == null)
         throw new ArgumentNullException("eventRegistration");
     if (attendee == null)
         throw new ArgumentNullException("attendee");
     EventRegistration = eventRegistration;
     EventOccurrence = eventOccurrence;
     FirstName = attendee.Name.FirstName;
     LastName = attendee.Name.LastName;
     Address1 = attendee.Address.Line1;
     Address2 = attendee.Address.Line2;
     City = attendee.Address.City;
     PostalCode = attendee.Address.PostalCode;
     StateId = attendee.Address.StateId;
     PrimaryPhone = attendee.Phone.Value;
     EmailAddress = attendee.Email.Value;
     DynamicColumnData = attendee.DynamicColumnData;
     ProfileId = attendee.ProfileId;
     UserId = attendee.UserId;
     DidAttend = attendee.DidAttend;
     DiscountCodeId = attendee.DiscountCodeId;
 }
Example #2
0
 private static int CalculateAvailableSeats(EventOccurrence occurrence)
 {
     return (occurrence.MaximumAttendees.HasValue ?
         ((occurrence.MaximumAttendees.Value - occurrence.EventOccurrenceAttendees.Count < 1) ?
             0 :
             (occurrence.MaximumAttendees.Value - occurrence.EventOccurrenceAttendees.Count)) :
         0);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="EventOccurrenceMapper"/> class.
 /// </summary>
 /// <param name="theEventOccurrence">The event occurrence.</param>
 public EventOccurrenceMapper(EventOccurrence theEventOccurrence)
 {
     if (theEventOccurrence == null)
     {
         throw new ArgumentNullException("theEventOccurrence");
     }
     _eventOccurrence = theEventOccurrence;
 }
        public void TestAddDate_Multiple()
        {
            var occurrence = new EventOccurrence() { Event = new Event() };
            occurrence.AddOccurrenceDate(new DateTime(2000, 1, 1), null);
            occurrence.AddOccurrenceDate(new DateTime(2000, 1, 2), null);
            occurrence.AddOccurrenceDate(new DateTime(2000, 1, 3), null);

            Assert.AreEqual(3, occurrence.EventOccurrenceDates.Count);
        }
        private static void SetDefaultRegistrationDates(EventOccurrence occurrence, DateRange occurrenceDate)
        {
            DateTime startDate = DateTime.UtcNow.Date;
            if (occurrenceDate.Start.Date <= DateTime.UtcNow.Date)
                startDate = occurrenceDate.Start.Date.AddDays(-1);

            DateTime endDate = occurrenceDate.End.Date;
            occurrence.SetRegistrationDates(startDate, endDate);
        }
 internal EventOccurrenceDate(EventOccurrence occurrence, DateTime startDate, DateTime? endDate)
 {
     EventOccurrence = occurrence;
     StartDate = startDate;
     if (endDate.HasValue && DateTime.Compare(StartDate, endDate.Value) >= 0)
     {
         throw new BusinessException("End time must be after start time.");
     }
     EndDate = endDate;
 }
 private EventOccurrence CreateTargetOccurrence()
 {
     var occurrence = new EventOccurrence();
     occurrence.OrgUnit = new OrgUnit();
     occurrence.OrgUnit.OrgUnitPublished = new OrgUnitPublished();
     occurrence.OrgUnit.OrgUnitPublished.Name = "OtherLocation";
     occurrence.OrgUnit.OrgUnitPublished.StateId = 1;
     occurrence.Event = new Event(){Id = 2};
     occurrence.Event.Title = "Other Event";
     return occurrence;
 }
 private EventOccurrenceAttendee CreateAttendee()
 {
     var occurrence = new EventOccurrence();
     occurrence.OrgUnit = new OrgUnit();
     occurrence.OrgUnit.OrgUnitPublished = new OrgUnitPublished();
     occurrence.OrgUnit.OrgUnitPublished.Name = "TestLocation";
     occurrence.Event = new Event() { Id = 1 };
     occurrence.Event.Title = "Test Event";
     occurrence.RegisterAttendee(new EventRegistration("transId"), new EventAttendee(new PersonName("John", "Doe"), new Address("123 Main St.", "Apt 2.", "Hoover", 1, "90036"), new EmailAddress("*****@*****.**"), new PhoneNumber("333-444-5555"), "John", "Doe"), 0M, false);
     return occurrence.EventOccurrenceAttendees.ElementAt(0);
 }
        public void TestAddDate()
        {
            var occurrence = new EventOccurrence() { Event = new Event() };
            var start = new DateTime(2000, 1, 1);
            var end = new DateTime(2000, 1, 2);
            occurrence.AddOccurrenceDate(start, end);
            Assert.AreEqual(1, occurrence.EventOccurrenceDates.Count);
            Assert.AreEqual(start, occurrence.EventOccurrenceDates.ElementAt(0).StartDate);
            Assert.AreEqual(end, occurrence.EventOccurrenceDates.ElementAt(0).EndDate);

            Assert.Greater(occurrence.LastUpdated, DateTime.MinValue);
        }
Example #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EventMobileMapper"/> class.
 /// </summary>
 /// <param name="eventOccurrenceEntity">The event occurrence entity.</param>
 /// <param name="clock">The clock.</param>
 public EventMobileMapper(EventOccurrence eventOccurrenceEntity, IClock clock)
 {
     if (eventOccurrenceEntity == null)
     {
         throw new ArgumentNullException("eventOccurrenceEntity");
     }
     if (clock == null)
     {
         throw new ArgumentNullException("clock");
     }
     _eventOccurrence = eventOccurrenceEntity;
     _clock = clock;
 }
 public static IEnumerable<EventOccurrence> GenerateOccurrences(IEnumerable<ScheduleEntry> scheduleEntries)
 {
     List<EventOccurrence> series = new List<EventOccurrence>();
     foreach (var scheduleEntry in scheduleEntries)
     {
         var occurence = new EventOccurrence();
         var dateRange = scheduleEntry.AsDateRange();
         occurence.AddOccurrenceDate(dateRange.Start, dateRange.End);
         SetDefaultRegistrationDates(occurence, dateRange);
         series.Add(occurence);
     }
     return series;
 }
        public static void CaptureCostScheduleData(EventOccurrenceV2 source, EventOccurrence target)
        {
            Decimal? sourceEarlyCost = GetDecimalValue(source.EarlyCost);
            var sourceEarlyCostEndDate = GetDateTime(source.EarlyCostEndDate);
            var sourceEarlyCostEndDays = GetNullableInt(source.EarlyCostEndDays);

            var earlyScheduleHasNecessaryValues = sourceEarlyCost.HasValue && (sourceEarlyCostEndDate.HasValue || sourceEarlyCostEndDays.HasValue);

            if (earlyScheduleHasNecessaryValues)
            {
                var hasEarlyDateValue = sourceEarlyCostEndDate.HasValue;
                if (hasEarlyDateValue)
                {
                    var EarlyCostPriceSchedule = new PricingSchedule(sourceEarlyCost.Value, sourceEarlyCostEndDate.Value);
                    target.SetEarlyRegistrationPrice(EarlyCostPriceSchedule);
                }
                else
                {
                    var EarlyCostPriceSchedule = new PricingSchedule(sourceEarlyCost.Value, sourceEarlyCostEndDays.Value);
                    target.SetEarlyRegistrationPrice(EarlyCostPriceSchedule);
                }
            }
            else
            {
                target.SetEarlyRegistrationPrice(null);
            }

            Decimal? sourceLateCost = GetDecimalValue(source.LateCost);
            var sourceLateCostStartDate = GetDateTime(source.LateCostStartDate);
            var sourceLateCostStartDays = GetNullableInt(source.LateCostStartDays);

            var lateScheduleHasNecessaryValues = sourceLateCost.HasValue && (sourceLateCostStartDate.HasValue || sourceLateCostStartDays.HasValue);
            if (lateScheduleHasNecessaryValues)
            {
                var hasLateDateValue = sourceLateCostStartDate.HasValue;
                if (hasLateDateValue)
                {
                    var LateCostPriceSchedule = new PricingSchedule(sourceLateCost.Value, sourceLateCostStartDate.Value);
                    target.SetLateRegistrationPrice(LateCostPriceSchedule);
                }
                else
                {
                    var LateCostPriceSchedule = new PricingSchedule(sourceLateCost.Value, sourceLateCostStartDays.Value);
                    target.SetLateRegistrationPrice(LateCostPriceSchedule);
                }
            }
            else
            {
                target.SetLateRegistrationPrice(null);
            }
        }
        public void TesEffectiveMaximumAttendees()
        {
            var ev = new Event();

            var occurrence = new EventOccurrence();
            occurrence.Event = ev;
            Assert.IsNull(occurrence.EffectiveMaximumAttendees);

            ev.MaximumAttendees = 20;
            Assert.AreEqual(20, occurrence.EffectiveMaximumAttendees);

            occurrence.MaximumAttendees = 10;
            Assert.AreEqual(10, occurrence.EffectiveMaximumAttendees);
        }
        /// <summary>
        /// Registers the attended for the specific event.
        /// </summary>
        /// <param name="occurence">The event occurence.</param>
        /// <param name="registration">The event registration.</param>
        /// <param name="attendee">The attendee.</param>
        /// <param name="amountPaid">The amount paid.</param>
        /// <param name="userProfile">The user profile.</param>
        /// <param name="sessionId">The session id.</param>
        /// <param name="context">The Object Context</param>
        /// <param name="discountCode">The Discount Code used</param>
        /// <param name="forcePayLater">Flag weather or not to force the PaymentRequired to true</param>
        public static void Add(EventOccurrence occurence, EventRegistration registration, EventAttendee attendee, decimal amountPaid, UserProfile userProfile, string sessionId, ObjectContext context, string discountCode, bool forcePayLater)
        {
            if (!string.IsNullOrEmpty(discountCode))
                attendee.DiscountCodeId = FindDiscountCodeId(discountCode, occurence.Id, context);

            var paymentRequired = (forcePayLater || occurence.AllowPayOnSite && amountPaid == 0 && occurence.Cost > 0) ? true : false;
            occurence.RegisterAttendee(registration, attendee, amountPaid, paymentRequired);
            AddActivity(userProfile, attendee.Name, occurence, sessionId);

            UpdateProfileEventCart(userProfile);

            var notificationSubscriber = occurence.EventOccurrenceNotifications.SingleOrDefault(n => string.Equals(n.Email, attendee.Email.Value, System.StringComparison.OrdinalIgnoreCase));
            if (notificationSubscriber != null)
                context.DeleteObject(notificationSubscriber);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="RescheduleAttendeeEmail"/> class.
 /// </summary>
 /// <param name="attendee">The attendee.</param>
 /// <param name="targetEventOccurrence">The target event occurrence.</param>
 public RescheduleAttendeeEmail(EventOccurrenceAttendee attendee, EventOccurrence targetEventOccurrence)
 {
     ToAddress = attendee.EmailAddress;
     TokenData = new
     {
         AttendeeName = attendee.Attendee.Name,
         PreviousEventTitle = attendee.EventOccurrence.Event.Title,
         PreviousEventStartDate = attendee.EventOccurrence.StartDate != null ? attendee.EventOccurrence.StartDate.Value.ToLongDateString() : "(unscheduled)",
         PreviousLocationName = attendee.EventOccurrence.EffectiveLocationName,
         NewEventTitle = targetEventOccurrence.Event.Title,
         NewEventStartDate = targetEventOccurrence.StartDate != null ? targetEventOccurrence.StartDate.Value.ToLongDateString() : "(unscheduled)",
         NewLocationName = targetEventOccurrence.EffectiveLocationName,
         NewLocationAddress = targetEventOccurrence.EffectiveCompleteAddress,
         NewDates = GetNewDatesTemplateContext(targetEventOccurrence)
     };
 }
        public void FilterByOccurrenceDates_excludes_where_occurrence_has_all_future_dates_but_is_disabled()
        {
            //setup
            //event with one disabled occurrence with all dates in future (should not be in search results)
            var theEvent = new Event { Id = 1 };
            var occurence = new EventOccurrence { IsEnabled = false };
            occurence.AddOccurrenceDate(_clock.Now.AddDays(1), null);
            occurence.AddOccurrenceDate(_clock.Now.AddDays(2), null);
            theEvent.EventOccurrences.Add(occurence);
            _objectSet.Add(theEvent);

            //act
            var result = _objectSet.AsQueryable().FilterByOccurrenceDates(null, null, _clock);

            //assert
            AssertExcluded(result, 1);
        }
        public void TestAddDate_DisablePricingSchedule()
        {
            var occurrence = new EventOccurrence() { Event = new Event() };
            occurrence.AddOccurrenceDate(new DateTime(2000, 1, 1), new DateTime(2000, 1, 2));

            var earlySchedule = new PricingSchedule(10M, new DateTime(1999, 01, 01));
            occurrence.SetEarlyRegistrationPrice(earlySchedule);

            var lateSchedule = new PricingSchedule(10M, new DateTime(1999, 12, 01));
            occurrence.SetEarlyRegistrationPrice(earlySchedule);

            occurrence.EnablePricingSchedule();

            occurrence.AddOccurrenceDate(new DateTime(1999, 12, 30), new DateTime(1999, 12, 31));

            Assert.IsFalse(occurrence.IsPriceScheduleEnabled);
        }
        private static void CaptureCostScheduleData(EventOccurrence source, EventOccurrence target)
        {
            var earlyScheduleHasNecessaryValues = source.EarlyCost.HasValue && (source.EarlyCostEndDate.HasValue || source.EarlyCostEndDays.HasValue);

            if (earlyScheduleHasNecessaryValues)
            {
                var hasEarlyDateValue = source.EarlyCostEndDate.HasValue;
                if (hasEarlyDateValue)
                {
                    var EarlyCostPriceSchedule = new PricingSchedule(source.EarlyCost.Value, source.EarlyCostEndDate.Value);
                    target.SetEarlyRegistrationPrice(EarlyCostPriceSchedule);
                }
                else
                {
                    var EarlyCostPriceSchedule = new PricingSchedule(source.EarlyCost.Value, source.EarlyCostEndDays.Value);
                    target.SetEarlyRegistrationPrice(EarlyCostPriceSchedule);
                }
            }
            else
            {
                target.SetEarlyRegistrationPrice(null);
            }

            var lateScheduleHasNecessaryValues = source.LateCost.HasValue && (source.LateCostStartDate.HasValue || source.LateCostStartDays.HasValue);
            if (lateScheduleHasNecessaryValues)
            {
                var hasLateDateValue = source.LateCostStartDate.HasValue;
                if (hasLateDateValue)
                {
                    var LateCostPriceSchedule = new PricingSchedule(source.LateCost.Value, source.LateCostStartDate.Value);
                    target.SetLateRegistrationPrice(LateCostPriceSchedule);
                }
                else
                {
                    var LateCostPriceSchedule = new PricingSchedule(source.LateCost.Value, source.LateCostStartDays.Value);
                    target.SetLateRegistrationPrice(LateCostPriceSchedule);
                }
            }
            else
            {
                target.SetLateRegistrationPrice(null);
            }
        }
        public void FilterByOccurrenceDates_excludes_where_occurrence_has_all_future_dates_but_out_of_range_end()
        {
            //setup
            var searchEndDate = _clock.Now.AddDays(10);

            //event with one occurrence with all dates in future (should not be in search results that specify an earlier date range)
            var theEvent = new Event { Id = 1 };
            var occurence = new EventOccurrence { IsEnabled = true };
            occurence.AddOccurrenceDate(_clock.Now.AddDays(11), null);
            occurence.AddOccurrenceDate(_clock.Now.AddDays(12), null);
            theEvent.EventOccurrences.Add(occurence);
            _objectSet.Add(theEvent);

            //act
            var result = _objectSet.AsQueryable().FilterByOccurrenceDates(null, searchEndDate, _clock);

            //assert
            AssertExcluded(result, 1);
        }
        public void TestConstruction()
        {
            var registration = new EventRegistration("test");
            var occurrence = new EventOccurrence() { Id = 1 };
            var attendee = CreateAttendee("John", "Doe");
            var subject = new EventOccurrenceAttendee(occurrence, registration, attendee);
            Assert.AreEqual(occurrence, subject.EventOccurrence);
            Assert.AreEqual(attendee, subject.Attendee);

            //TODO: the primitive properties of EventOccurrenceAttendee should be made protected eventually, so these assertions won't be possible or necessary.
            Assert.AreEqual(attendee.Name.FirstName, subject.FirstName);
            Assert.AreEqual(attendee.Name.LastName, subject.LastName);
            Assert.AreEqual(attendee.Address.Line1, subject.Address1);
            Assert.AreEqual(attendee.Address.Line2, subject.Address2);
            Assert.AreEqual(attendee.Address.PostalCode, subject.PostalCode);
            Assert.AreEqual(attendee.Address.City, subject.City);
            Assert.AreEqual(attendee.Address.StateId, subject.StateId);
            Assert.AreEqual(attendee.Email.Value, subject.EmailAddress);
            Assert.AreEqual(attendee.Phone.Value, subject.PrimaryPhone);
        }
Example #21
0
        private static void MapOccurrenceDates(EventSearchResultPortalDto result, EventOccurrence occurrence)
        {
            var occurrenceDate = occurrence.EventOccurrenceDates.OrderBy(o => o.StartDate).First();

            result.StartDateFormatted = occurrenceDate.StartDate.ToLongDateString();
            result.OccurenceMonthYear = string.Concat(occurrenceDate.StartDate.ToString("MMMM", CultureInfo.CurrentCulture), " ", occurrenceDate.StartDate.ToString("yyyy", CultureInfo.CurrentCulture));
            result.StartTimeFormatted = occurrenceDate.StartDate.ToShortTimeString();
            result.EndDateFormatted = occurrenceDate.EndDate.HasValue ? occurrenceDate.EndDate.Value.ToShortTimeString() : string.Empty;
            int occurrenceCount = occurrence.EventOccurrenceDates.Count();
            if (occurrenceCount > 1)
            {
                result.StartDateFormatted = occurrenceDate.StartDate.ToString("MMMM dd, yyyy", CultureInfo.CurrentCulture);

                occurrenceDate = occurrence.EventOccurrenceDates.OrderBy(e => e.EndDate).Last();
                if (occurrenceDate.EndDate.HasValue)
                {
                    result.EndDateFormatted = occurrenceDate.EndDate.Value.ToString("MMMM dd, yyyy", CultureInfo.CurrentCulture) + " (" + occurrenceCount.ToString(CultureInfo.CurrentCulture) + ")";
                }
            }
        }
        public static void AddExternalIdMapping(ObjectContext context, EventOccurrenceV2 source, EventOccurrence target)
        {
            if (!string.IsNullOrEmpty(source.OccurrenceExternalId))
            {
                var mappingExists = context.CreateObjectSet<DataImportEntityIdMap>()
                    .Any(m => m.EntityName == "EventOccurrence" &&
                    m.InternalId == target.Id &&
                    m.ExternalId == source.OccurrenceExternalId);

                if (!mappingExists)
                {
                    context.AddObject("DataImportEntityIdMaps", new DataImportEntityIdMap
                    {
                        EntityName = "EventOccurrence",
                        DataImportId = 2,
                        InternalId = target.Id,
                        ExternalId = source.OccurrenceExternalId
                    });
                    context.SaveChanges();
                }
            }
        }
        public void filter_removes_occurrences_with_dates_in_past()
        {
            var objectSet = new List<EventOccurrence>();

            //occurrence with dates in past, present, future (should not be included in result)
            var occurence = new EventOccurrence { Id = 1 };
            occurence.AddOccurrenceDate(_clock.Now.AddDays(-2), null);
            occurence.AddOccurrenceDate(_clock.Now.AddDays(-1), null);
            occurence.AddOccurrenceDate(_clock.Now, null);
            occurence.AddOccurrenceDate(_clock.Now.AddDays(1), null);
            occurence.AddOccurrenceDate(_clock.Now.AddDays(2), null);
            objectSet.Add(occurence);

            //occurrence with dates all in future (should be included in result)
            occurence = new EventOccurrence { Id = 2 };
            occurence.AddOccurrenceDate(_clock.Now.AddDays(1), null);
            occurence.AddOccurrenceDate(_clock.Now.AddDays(2), null);
            objectSet.Add(occurence);

            var result = objectSet.AsQueryable().FilterByOccurrenceDates(null, null, _clock);

            Assert.AreEqual(1, result.Count());
            Assert.AreEqual(2, result.ElementAt(0).Id);
        }
 private void AssertSeriesOccurrencePropertiesSetCorrectly(EventOccurrence occurrence)
 {
     Assert.IsNotNull(occurrence.SeriesEventOccurrenceId);
     Assert.IsTrue(occurrence.IsPartOfSeries);
     Assert.AreEqual(_orgUnitId, occurrence.OrgUnitId);
     Assert.AreEqual(_presenter, occurrence.Presenter);
     Assert.AreEqual(_contactEmail, occurrence.ContactEmail);
     Assert.AreEqual(_contactName, occurrence.ContactName);
     Assert.AreEqual(_contactPhone, occurrence.ContactPhone);
     Assert.AreEqual(_isEnabled, occurrence.IsEnabled);
     Assert.AreEqual(_isNotificationListEnabled, occurrence.IsNotificationListEnabled);
     Assert.AreEqual(_isRegistrationEnabled, occurrence.IsNotificationListEnabled);
     Assert.AreEqual(1, occurrence.EventOccurrenceDates.Count);
 }
 private static EventOccurrenceDate Construct(DateTime start, DateTime? end)
 {
     var occurrence = new EventOccurrence() { Event = new Event() };
     return new EventOccurrenceDate(occurrence, start, end);
 }
        private static void FormatEventInfo(EventOccurrence eventOccurrence,
			out string eventTitle,
			out string eventDateTime,
			out string eventEffectiveLocationName,
			out string eventEffectiveAddress,
			out string eventSpecialInstructions,
			out string eventOccurrenceSpecialInstructions)
        {
            eventTitle = eventOccurrence.Event.Title;

            eventDateTime = string.Empty;
            if (eventOccurrence.StartDate.HasValue)
                eventDateTime = eventOccurrence.StartDate.Value.ToString("ddd, MMM d, yyyy h:mm tt", CultureInfo.InvariantCulture);

            var eventEndDate = string.Empty;
            if (eventOccurrence.EndDate.HasValue)
            {
                eventEndDate = eventOccurrence.EndDate.Value.ToString("h:mm tt", CultureInfo.InvariantCulture);
                eventDateTime += " - " + eventEndDate;
            }

            eventEffectiveLocationName = eventOccurrence.EffectiveLocationName;
            var eventEffectiveAddress1 = eventOccurrence.EffectiveAddress1;

            var eventEffectiveAddress2 = string.Empty;
            if (!string.IsNullOrEmpty(eventOccurrence.EffectiveAddress2))
                eventEffectiveAddress2 = eventOccurrence.EffectiveAddress2;

            var state = eventOccurrence.EffectiveState != null ? eventOccurrence.EffectiveState.Name : string.Empty;

            var eventCityStatePostalCode = string.Format(CultureInfo.InvariantCulture, "{0},{1} {2}",
                                                    eventOccurrence.EffectiveCity, state, eventOccurrence.EffectivePostalCode);

            eventEffectiveAddress = string.Format(CultureInfo.InvariantCulture, "{0} {1} {2}",
                                                    eventEffectiveAddress1, eventEffectiveAddress2, eventCityStatePostalCode);

            eventSpecialInstructions = string.Empty;
            eventOccurrenceSpecialInstructions = string.Empty;
            if (!string.IsNullOrEmpty(eventOccurrence.SpecialInstructions) || !string.IsNullOrEmpty(eventOccurrence.Event.SpecialInstructions))
            {
                if (!string.IsNullOrEmpty(eventOccurrence.Event.SpecialInstructions))
                    eventSpecialInstructions = eventOccurrence.Event.SpecialInstructions;
                if (!string.IsNullOrEmpty(eventOccurrence.SpecialInstructions))
                    eventOccurrenceSpecialInstructions = eventOccurrence.SpecialInstructions;
            }
        }
        private static Attachment BuildRegistrantCsv(EventOccurrence eventOccurrence)
        {
            Attachment attachment = null;

            var stream = new MemoryStream();
            var sw = new StreamWriter(stream);
            var sb = new StringBuilder();
            var ifp = CultureInfo.InvariantCulture;

            var registrants = eventOccurrence.EventOccurrenceAttendees.OrderBy(r => r.LastName).ThenBy(r => r.FirstName);

            sb.AppendLine("Registrant Name,Address 1,Address 2,City,State,Zip Code,Email,Phone,Registration Date,Amount Paid,Transaction Id,Discount Code");
            foreach (var reg in registrants)
            {
                sb.AppendFormat(ifp, "\"{0}\"", reg.LastName + ", " + reg.FirstName);
                sb.AppendFormat(ifp, ",\"{0}\"", reg.Address1);
                sb.AppendFormat(ifp, ",\"{0}\"", reg.Address2);
                sb.AppendFormat(ifp, ",\"{0}\"", reg.City);
                sb.AppendFormat(ifp, ",\"{0}\"", reg.State != null ? reg.State.Name : string.Empty);
                sb.AppendFormat(ifp, ",\"{0}\"", reg.PostalCode);
                sb.AppendFormat(ifp, ",\"{0}\"", reg.EmailAddress);
                sb.AppendFormat(ifp, ",\"{0}\"", reg.PrimaryPhone);
                sb.AppendFormat(ifp, ",\"{0}\"", reg.EventRegistration.RegistrationDate.ToString(ifp));
                sb.AppendFormat(ifp, ",\"{0}\"", reg.AmountPaid.ToString("$0.00", ifp));
                sb.AppendFormat(ifp, ",\"{0}\"", reg.EventRegistration.TransactionId);
                sb.AppendFormat(ifp, ",\"{0}\"", reg.DiscountCode != null ? reg.DiscountCode.Code : string.Empty);
                sb.AppendLine();
            }

            sw.Write(sb.ToString());
            sw.Flush();
            stream.Position = 0;

            attachment = new Attachment(stream, "Event Registration Report.csv", "text/csv");

            return attachment;
        }
        /// <summary>
        /// Adds an activity to the profile.
        /// </summary>
        /// <param name="userProfile">The user profile.</param>
        /// <param name="registrantName">Name of the registrant.</param>
        /// <param name="eventOccurrence">The event occurrence.</param>
        /// <param name="sessionId">The session id.</param>
        private static void AddActivity(UserProfile userProfile, PersonName registrantName, EventOccurrence eventOccurrence, string sessionId)
        {
            if (userProfile != null)
            {
                var location = eventOccurrence.OrgUnit != null ? eventOccurrence.OrgUnit.Name : string.Empty;
                var eventTitle = eventOccurrence.Event != null ? eventOccurrence.Event.Title : string.Empty;

                var activityDescription = string.Format(CultureInfo.InvariantCulture, ProfileActivityConstants.ActivityEventRegistration, registrantName, eventTitle, location);

                userProfile.Profile.AddActivity(userProfile.UserId, activityDescription, sessionId);
            }
        }
        public static void HandleEventOccurrenceNotificationEmails(EventOccurrence eventOccurrence, IEmailProcessor emailProcessor, string hostUrl)
        {
            var contactEmails = !string.IsNullOrEmpty(eventOccurrence.Event.ContactEmail) ? eventOccurrence.Event.ContactEmail.Split(';').Select(e => e.Trim()) : new List<string>();

            if (eventOccurrence.IsNotifyContactEnabled && !string.IsNullOrEmpty(eventOccurrence.ContactEmail))
                contactEmails = contactEmails.Union(eventOccurrence.ContactEmail.Split(';').Select(e => e.Trim()));

            var attachmentList = new List<Attachment>();
            attachmentList.Add(BuildRegistrantCsv(eventOccurrence));

            List<IEmailContext> emailList = new List<IEmailContext>();
            foreach (var email in contactEmails)
            {
                int remainingSeats = -1;
                if (eventOccurrence.MaximumAttendees.HasValue)
                    remainingSeats = eventOccurrence.MaximumAttendees.Value - eventOccurrence.EventOccurrenceAttendees.Count;

                var contactEmail = new RegistrationNotificationEmail(email,
                    eventOccurrence.Event.Title,
                    eventOccurrence.StartDate,
                    eventOccurrence.OrgUnit.Name,
                    remainingSeats,
                    hostUrl + "/sites/staff/_layouts/MEDSEEK/ENRS/Admin/Reports/ConsolidatedReport.aspx?Keyword=" + HttpUtility.UrlEncode(eventOccurrence.Event.Title));

                contactEmail.Attachments = attachmentList;

                emailList.Add(contactEmail);
            }
            emailProcessor.ProcessBatch(emailList);
        }
        public static void CapturePropertiesForAdd(ObjectContext context, EventOccurrenceV2 source, EventOccurrence target)
        {
            if (!string.IsNullOrEmpty(source.CostCenter) && source.CostCenter.Length > 15)
                throw new BusinessException("Error processing the event occurrence for event '" + target.Event.Title + "' - Cost center cannot be longer than 15 characaters");

            target.ContactName = source.ContactName;
            target.ContactEmail = source.ContactEmail;
            target.ContactPhone = source.ContactPhone;

            target.CostCenter = source.CostCenter;
            target.Cost = GetDecimalValue(source.Cost);

            target.MaximumAttendees = GetNullableInt(source.MaximumAttendees);
            target.LastUpdated = DateTime.UtcNow;

            if(!string.IsNullOrEmpty(source.Presenter))
                target.SetPresenter(source.Presenter);
            target.SetIsEnabled(GetBooleanValue(source.IsEnabled));

            target.IsRegistrationEnabled = GetBooleanValue(source.IsRegistrationEnabled);
            target.IsNotificationListEnabled = GetBooleanValue(source.IsNotificationListEnabled);

            target.IsNotifyContactEnabled = GetBooleanValue(source.IsNotifyContactEnabled);

            target.OrgUnitId = ResolveOrgUnitId(context, source.OrgUnitId, source.OrgUnitExternalId);

            target.SpecialInstructions = source.SpecialInstructions;

            if (!string.IsNullOrEmpty(source.LocationName))
            {
                target.LocationName = source.LocationName;
                target.Address1 = source.Address1;
                target.Address2 = source.Address2;
                target.City = source.City;
                target.StateId = LookupStateId(context, source.State);
                target.CountryId = LookupCountryId(context, source.Country);
                target.PostalCode = source.PostalCode;
                target.Latitude = GetNullableDecimal(source.Latitude);
                target.Longitude = GetNullableDecimal(source.Longitude);
            }
            else
            {
                target.LocationOrgUnitId = ResolveOrgUnitId(context, source.LocationOrgUnitId, source.LocationOrgUnitExternalId);
            }

            target.AllowPayOnSite = GetBooleanValue(source.AllowPayOnSite);
        }