public void TestSetPresenterInvalidValue()
 {
     var occurrence = new EventOccurrence();
     occurrence.SetPresenter(new String('X', 256));
 }
        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);
        }
        public static EventOccurrence BuildNewOccurrence(ObjectContext objectContext, int newEventId, EventOccurrence item)
        {
            var newOccurrence = new EventOccurrence
            {
                ContactName = item.ContactName,
                ContactEmail = item.ContactEmail,
                ContactPhone = item.ContactPhone,
                ContactPhoneExtension = item.ContactPhoneExtension,
                Cost = item.Cost,
                CostCenter = item.CostCenter,
                OrgUnitId = item.OrgUnitId,
                MaximumAttendees = item.MaximumAttendees,
                LastUpdated = System.DateTime.UtcNow,
                PaymentProcessorConfigurationId = item.PaymentProcessorConfigurationId,
                IsRegistrationEnabled = item.IsRegistrationEnabled,
                IsNotificationListEnabled = item.IsNotificationListEnabled,
                IsNotifyContactEnabled = item.IsNotifyContactEnabled,
                SpecialInstructions = item.SpecialInstructions,
                LocationOrgUnitId = item.LocationOrgUnitId,
                LocationName = item.LocationName,
                Address1 = item.Address1,
                Address2 = item.Address2,
                City = item.City,
                PostalCode = item.PostalCode,
                StateId = item.StateId,
                CountryId = item.CountryId,
                Latitude = item.Latitude,
                Longitude = item.Longitude,
                IsGuestDemographicInfoRequired = item.IsGuestDemographicInfoRequired
            };

            newOccurrence.SetPresenter(item.Presenter);
            newOccurrence.SetIsEnabled(item.IsEnabled);
            newOccurrence.SetEventId(newEventId);

            newOccurrence.SetAddress1(item.Address1);
            newOccurrence.SetAddress2(item.Address2);

            newOccurrence.SetRegistrationDates(item.RegistrationStartDate, item.RegistrationEndDate);

            if (item.IsPriceScheduleEnabled)
                newOccurrence.EnablePricingSchedule();
            else
                newOccurrence.DisablePricingSchedule();

            CaptureCostScheduleData(item, newOccurrence);

            objectContext.AddObject("EventOccurrences", newOccurrence);
            objectContext.SaveChanges();

            //event occurrence documents
            foreach (var doc in item.EventOccurrencesDocuments)
            {
                var newDoc = new EventOccurrencesDocument()
                {
                    DocumentPath = doc.DocumentPath,
                    EventOccurrence = newOccurrence
                };
                newOccurrence.EventOccurrencesDocuments.Add(newDoc);
            }

            //event occurrence dates
            foreach (var dateItem in item.EventOccurrenceDates)
            {
                newOccurrence.AddOccurrenceDate(dateItem.StartDate, dateItem.EndDate);
            }
            objectContext.SaveChanges();

            return newOccurrence;
        }