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 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 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 void SetRegistrationDates(EventOccurrenceV2 source, EventOccurrence target) { if (string.IsNullOrEmpty(source.RegistrationStartDate)) return; var start = GetDateTime(source.RegistrationStartDate); var end = GetDateTime(source.RegistrationEndDate); target.SetRegistrationDates(start, end); }
public static void SetPricingSchedule(EventOccurrenceV2 source, EventOccurrence target) { //Must do this after setting early and late cost if (GetBooleanValue(source.IsPriceScheduleEnabled)) { target.EnablePricingSchedule(); } else { target.DisablePricingSchedule(); } }
public static void SetPaymentProcessorId(ObjectContext context, EventOccurrenceV2 source, EventOccurrence target) { if (source.PaymentProcessorConfigurationId == null) return; target.PaymentProcessorConfigurationId = GetNullableInt(source.PaymentProcessorConfigurationId); //being blank is ok, but do not need to check for PaymentProcessorConfiguration existence if (source.PaymentProcessorConfigurationId.Length == 0) return; var payment = context.CreateObjectSet<PaymentProcessorConfiguration>().Any(o => o.Id == target.PaymentProcessorConfigurationId); if (!payment) { throw new BusinessException("There was no Payment Processor Configurations found with the provided PaymentProcessorConfigurationId."); } }
public static void SetOccurrenceDates(ObjectContext context, EventOccurrenceV2 source, EventOccurrence target) { if (source.EventOccurrenceDates == null) return; try { //remove all dates, we add all dates in source below var existingDates = target.EventOccurrenceDates.ToArray(); foreach (var item in existingDates) context.DeleteObject(item); //Add occurrence date to the target foreach (var item in source.EventOccurrenceDates) { target.AddOccurrenceDate(GetDateTime(item.StartDate).Value, GetDateTime(item.EndDate)); } } catch (Exception ex) { throw new BusinessException("Error processing event occurrence dates - " + ex.Message, ex); } }
public static void SetFirstOccurrenceDates(EventOccurrenceV2 source, EventOccurrence target) { if (string.IsNullOrEmpty(source.FirstOccurrenceDateStart)) return; var start = GetDateTime(source.FirstOccurrenceDateStart); var end = GetDateTime(source.FirstOccurrenceDateEnd); if (start.HasValue) target.AddOccurrenceDate(start.Value, end); }
public static void SetEvent(ObjectContext context, EventOccurrenceV2 source, EventOccurrence target) { int eventId = -1; Event theEvent = null; if (int.TryParse(source.EventId, out eventId)) { theEvent = context.CreateObjectSet<Event>().SingleOrDefault(e => e.Id == eventId); } else if (!string.IsNullOrEmpty(source.EventExternalId)) { var mapping = context.CreateObjectSet<DataImportEntityIdMap>().SingleOrDefault(m => m.ExternalId == source.EventExternalId && m.EntityName == "Event"); if (mapping != null) { theEvent = context.CreateObjectSet<Event>().Single(e => e.Id == mapping.InternalId); } } if (theEvent == null) { throw new BusinessException("Cannot find the event based on the EventId or the EventExternalId"); } target.Event = theEvent; target.SetEventId(theEvent.Id); }
public static void SetDyanmicFormsId(ObjectContext context, EventOccurrenceV2 source, EventOccurrence target) { if (source.DynamicFormsId == null) return; target.DynamicFormsId = GetNullableInt(source.DynamicFormsId); //being blank is ok, but do not need to check for form existence if (source.DynamicFormsId.Length == 0) return; var form = context.CreateObjectSet<DynamicForm>().Any(d => d.Id == target.DynamicFormsId); if (!form) { throw new BusinessException("There was no dynamic form id found with the provided DynamicFormsId."); } }
public static bool PublishOrgUnitEntityAssociation(EventOccurrenceV2 source) { return GetBooleanValue(source.PublishOrgUnitEntityAssociations); }
private string GetOccurrence(ConvertServiceRequest request) { var occurrenceId = 0; if (request.Parameters.ContainsKey("externalId")) { occurrenceId = LookupDataEntityMapId("EventOccurrence", request.Parameters["externalId"], false); } else if (request.Parameters.ContainsKey("id")) { if (!int.TryParse(request.Parameters["id"], out occurrenceId)) throw new BusinessException("Event Occurrence Id must be a valid integer"); } var occurrenceRequest = new ReadEventOccurrenceRequest() { Id = occurrenceId }; var occ = ProcessRequest<ReadEventOccurrenceResponse>(occurrenceRequest).EventOccurrence; var occurrence = new EventOccurrenceV2 { OccurrenceId = occ.Id.ToString(CultureInfo.InvariantCulture), EventId = occ.EventId.ToString(CultureInfo.InvariantCulture), EventExternalId = occ.EventExternalId, IsEnabled = occ.IsEnabled.ToString(CultureInfo.InvariantCulture), OrgUnitId = occ.OrgUnitId.HasValue ? occ.OrgUnitId.Value.ToString(CultureInfo.InvariantCulture) : null, OrgUnitExternalId = occ.OrgUnitExternalId, LocationOrgUnitId = occ.LocationOrgUnitId.HasValue ? occ.LocationOrgUnitId.Value.ToString(CultureInfo.InvariantCulture) : null, LocationOrgUnitExternalId = occ.LocationOrgUnitExternalId, LocationName = occ.LocationName, Address1 = occ.Address1, Address2 = occ.Address2, City = occ.City, State = occ.State, PostalCode = occ.PostalCode, Country = occ.CountryName, Latitude = occ.Latitude.HasValue ? occ.Latitude.Value.ToString(CultureInfo.InvariantCulture) : null, Longitude = occ.Longitude.HasValue ? occ.Longitude.Value.ToString(CultureInfo.InvariantCulture) : null, ContactName = occ.ContactName, ContactPhone = occ.ContactPhone, ContactEmail = occ.ContactEmail, MaximumAttendees = occ.MaximumAttendees.HasValue ? occ.MaximumAttendees.Value.ToString(CultureInfo.InvariantCulture) : null, Presenter = occ.Presenter, Cost = occ.Cost.HasValue ? occ.Cost.Value.ToString(CultureInfo.InvariantCulture) : null, CostCenter = occ.CostCenter, RegistrationStartDate = occ.RegistrationStartDate.HasValue ? occ.RegistrationStartDate.Value.ToString(CultureInfo.InvariantCulture) : null, RegistrationEndDate = occ.RegistrationEndDate.HasValue ? occ.RegistrationEndDate.Value.ToString(CultureInfo.InvariantCulture) : null, IsPriceScheduleEnabled = occ.IsPriceScheduleEnabled.ToString(CultureInfo.InvariantCulture), EarlyCost = occ.EarlyCost.HasValue ? occ.EarlyCost.Value.ToString(CultureInfo.InvariantCulture) : null, EarlyCostEndDate = occ.EarlyCostEndDate.HasValue ? occ.EarlyCostEndDate.Value.ToString(CultureInfo.InvariantCulture) : null, EarlyCostEndDays = occ.EarlyCostEndDays.HasValue ? occ.EarlyCostEndDays.Value.ToString(CultureInfo.InvariantCulture) : null, LateCost = occ.LateCost.HasValue ? occ.LateCost.Value.ToString(CultureInfo.InvariantCulture) : null, LateCostStartDate = occ.LateCostStartDate.HasValue ? occ.LateCostStartDate.Value.ToString(CultureInfo.InvariantCulture) : null, LateCostStartDays = occ.LateCostStartDays.HasValue ? occ.LateCostStartDays.Value.ToString(CultureInfo.InvariantCulture) : null, PaymentProcessorConfigurationId = occ.PaymentProcessorConfigurationId.HasValue ? occ.PaymentProcessorConfigurationId.Value.ToString(CultureInfo.InvariantCulture) : null, OccurrenceExternalId = occ.OccurrenceExternalId, IsRegistrationEnabled = occ.IsRegistrationEnabled.ToString(CultureInfo.InvariantCulture), IsNotificationListEnabled = occ.IsNotificationListEnabled.ToString(CultureInfo.InvariantCulture), IsNotifyContactEnabled = occ.IsNotifyContactEnabled.ToString(CultureInfo.InvariantCulture), SpecialInstructions = occ.SpecialInstructions, DynamicFormsId = occ.DynamicFormsId.HasValue ? occ.DynamicFormsId.Value.ToString(CultureInfo.InvariantCulture) : null, AllowPayOnSite = occ.AllowPayOnSite.ToString(CultureInfo.InvariantCulture), EventOccurrenceDates = occ.EventOccurrenceDates.Select(d => new EventOccurrenceDateV2 { StartDate = d.StartDate.HasValue ? d.StartDate.Value.ToString(CultureInfo.InvariantCulture) : null, EndDate = d.EndDate.HasValue ? d.EndDate.Value.ToString(CultureInfo.InvariantCulture) : null }).ToList() }; return CommonUtils.XmlSerialize(occurrence); }