public static void UpdateEventType(Event target, IEnumerable<int> eventTypeIds, ObjectContext objectContext) { if (eventTypeIds.Count() > 0) { target.EventTypeAssociations.ToList().ForEach(e => objectContext.DeleteObject(e)); foreach (var typeId in eventTypeIds) target.EventTypeAssociations.Add(new EventTypeAssociation() { EventTypeId = typeId, EventId = target.Id }); } else throw new BusinessException("Event Type requires at least one value"); }
/// <summary> /// Initializes a new instance of the <see cref="EventMobileMapper"/> class. /// </summary> /// <param name="eventEntity">The event entity.</param> /// <param name="clock">The clock.</param> public EventMobileMapper(Event eventEntity, IClock clock) { if (eventEntity == null) { throw new ArgumentNullException("eventEntity"); } if (clock == null) { throw new ArgumentNullException("clock"); } _event = eventEntity; _clock = clock; }
/// <summary> /// Initializes a new instance of the <see cref="EventPageTitle"/> class. /// </summary> /// <param name="theEvent">The event.</param> /// <param name="seoSettings">The seo settings.</param> public EventPageTitle(Event theEvent, SeoSettings seoSettings) { if (theEvent == null) { throw new ArgumentNullException("theEvent"); } if (seoSettings == null) { throw new ArgumentNullException("seoSettings"); } _event = theEvent; _seoSettings = seoSettings; }
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> /// Initializes a new instance of the <see cref="EventMapper"/> class. /// </summary> /// <param name="theEvent">The event.</param> /// <param name="clock">The clock.</param> public EventMapper(Event theEvent, IClock clock) { if (theEvent == null) { throw new ArgumentNullException("theEvent"); } if (clock == null) { throw new ArgumentNullException("clock"); } _clock = clock; _event = theEvent; _getActive = o => (o.IsEnabled == true && o.StartDate > _clock.Now && (o.OrgUnit.OrgUnitTypeAssociations.Count == 0 || o.OrgUnit.OrgUnitTypeAssociations.Any (ot => ot.OrgUnitType.IsOutsideOfOrganization == false))); }
public void TestIsPublished_UnpublishDateSet() { var unpublishDate = new DateTime(1999, 12, 31); var subject = new Event(); subject.PublishDate = null; subject.UnpublishDate = unpublishDate; var now = new DateTime(1999, 12, 30); Assert.IsTrue(subject.IsPublishedAsOf(now)); now = new DateTime(1999, 12, 31); Assert.IsTrue(subject.IsPublishedAsOf(now)); now = new DateTime(2000, 1, 1); Assert.IsFalse(subject.IsPublishedAsOf(now)); }
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 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); }
/// <summary> /// Determines whether the Event has a unique DirectUrl. /// </summary> /// <param name="entity">The event.</param> /// <param name="entitytContextFactory">The object context factory.</param> /// <returns> /// <c>true</c> if the Event has a unique DirectUrl; otherwise, <c>false</c>. /// </returns> public static bool HasUniqueDirectUrl(Event entity, IEntityContextFactory entitytContextFactory) { bool result; using (var context = entitytContextFactory.CreateEntityContext()) { var count = context.EntitySet<Event>().Count(e => e.DirectUrl == entity.DirectUrl && e.Id != entity.Id); if (count > 0) { throw new BusinessException( string.Format(CultureInfo.CurrentCulture, "There is already an Event with a direct url of \"{0}\".", entity.DirectUrl)); } result = true; } return result; }
public static void CapturePropertiesForAdd(EventV2 source, Event target) { if (!string.IsNullOrEmpty(source.CostCenter) && source.CostCenter.Length > 15) throw new BusinessException("Error processing the event '" + source.Title + "' - Cost center cannot be longer than 15 characaters"); target.ContactName = source.ContactName; target.ContactEmail = source.ContactEmail; target.ContactPhone = source.ContactPhone; target.MaximumAttendees = GetNullableInt(source.MaximumAttendees); target.Cost = Convert.ToDecimal(source.Cost, CultureInfo.InvariantCulture); target.UpdatedDate = DateTime.UtcNow; target.InternalOnly = GetBooleanValue(source.InternalOnly); target.IsEnabled = GetBooleanValue(source.IsEnabled); target.PublicOnly = GetBooleanValue(source.PublicOnly); target.ExternalUrl = source.ExternalUrl; target.ImagePath = source.ImagePath; target.PictureId = GetNullableInt(source.PictureId); target.SetTitle(source.Title); target.SetSummaryDescription(source.SummaryDescription); target.CostCenter = source.CostCenter; target.Keywords = source.Keywords; target.CustomKeywords = source.CustomKeywords; target.EventContent = source.EventContent; target.IsRegistrationEnabled = GetBooleanValue(source.IsRegistrationEnabled); target.IsNotificationListEnabled = GetBooleanValue(source.IsNotificationListEnabled); target.IsNotifyContactEnabled = GetBooleanValue(source.IsNotifyContactEnabled); target.NotificationFrequency = string.IsNullOrEmpty(source.NotificationFrequency) ? "Immediately" : source.NotificationFrequency; target.SpecialInstructions = source.SpecialInstructions; target.Custom1 = source.Custom1; target.Custom2 = source.Custom2; target.Custom3 = source.Custom3; DateTime? pubDate = string.IsNullOrEmpty(source.PublishDate) ? new DateTime?() : DateTime.Parse(source.PublishDate, CultureInfo.InvariantCulture); DateTime? unPubDate = string.IsNullOrEmpty(source.UnpublishDate) ? new DateTime?() : DateTime.Parse(source.UnpublishDate, CultureInfo.InvariantCulture); target.SetPublishDates(pubDate, unPubDate); target.AllowPayOnSite = GetBooleanValue(source.AllowPayOnSite); target.AllowDonation = source.AllowDonationAsBool; target.DonationDescription = source.DonationDescription; target.DonationButtonText = source.DonationButtonText; target.DonationExternalUrl = source.DonationExternalUrl; }
public static void AddExternalIdMapping(ObjectContext context, EventV2 source, Event theEvent) { if (!string.IsNullOrEmpty(source.EventExternalId)) { var existingMappings = context.CreateObjectSet<DataImportEntityIdMap>() .Where(m => m.EntityName == "Event" && m.InternalId == theEvent.Id) .ToList(); if (existingMappings.Count == 1) { if (existingMappings[0].ExternalId != source.EventExternalId) { // Update ExternalId on existing mapping existingMappings[0].ExternalId = source.EventExternalId; } } else { // Remove ambiguous mappings (if any) if (existingMappings.Count > 1) { foreach (var mapping in existingMappings) { context.DeleteObject(mapping); } } // Create new mapping context.AddObject("DataImportEntityIdMaps", new DataImportEntityIdMap { EntityName = "Event", DataImportId = 2, InternalId = theEvent.Id, ExternalId = source.EventExternalId }); } } }
public void TestIsPublished_RangeDefined() { var publishDate = new DateTime(1999, 12, 31); var unpublishDate = new DateTime(2000, 1, 2); var subject = new Event(); subject.PublishDate = publishDate; subject.UnpublishDate = unpublishDate; var now = new DateTime(1999, 12, 30); Assert.IsFalse(subject.IsPublishedAsOf(now)); now = new DateTime(1999, 12, 31); Assert.IsTrue(subject.IsPublishedAsOf(now)); now = new DateTime(2000, 1, 1); Assert.IsTrue(subject.IsPublishedAsOf(now)); now = new DateTime(2000, 1, 2); Assert.IsTrue(subject.IsPublishedAsOf(now)); now = new DateTime(2000, 1, 3); Assert.IsFalse(subject.IsPublishedAsOf(now)); }
public static void SetDynamicColumns(ObjectContext context, EventV2 source, Event evnt) { if (source.DynamicColumns == null) return; var existingDynamicColumns = context.CreateObjectSet<DynamicColumnEntity>() .First(d => d.EntityName == "Events") .DynamicColumnInstances; if (!existingDynamicColumns.Any()) evnt.DynamicColumnData = DynamicColumnUtility.ConvertFomList(new List<DynamicColumnDto>()); //Make sure column names specified are valid var invalidColumnNames = new List<string>(); foreach (var item in source.DynamicColumns) { var column = existingDynamicColumns.FirstOrDefault(d => d.Name == item.FieldName); if (column == null) invalidColumnNames.Add(item.FieldName); } if (invalidColumnNames.Any()) { var errorMessage = "Invalid Column Names Specified: " + string.Join(",", invalidColumnNames.ToArray()); throw new BusinessException("Error processing dynamic columns for event '" + evnt.Title + "' - " + errorMessage); } evnt.DynamicColumnData = DynamicColumnUtility.ConvertFomList(source.DynamicColumns); }
public static void SetDiscountCodes(ObjectContext context, EventV2 source, Event theEvent) { foreach (var eventCode in theEvent.EventDiscountCodes.ToList()) { context.DeleteObject(eventCode); } if (source.DiscountCodes == null || !source.DiscountCodes.Any()) return; var discountCodes = context.CreateObjectSet<DiscountCode>(); foreach (var discount in source.DiscountCodes) { if (string.IsNullOrEmpty(discount.Code)) throw new BusinessException("Code for discount code is required"); DiscountCode code = new DiscountCode(); //Check if org unit discount code exists if (theEvent.OrgUnitId.HasValue) code = FindOrgUnitDiscountCode(context, theEvent, discount); if (code == null) { //Check if event discount code exists code = FindEventDiscountCode(context, discount); if (code == null) { //If no discount with the given code is found, create a new event discount code if (string.IsNullOrEmpty(discount.DiscountType)) throw new BusinessException("Unable to add discount code. DiscountType is required"); if (string.IsNullOrEmpty(discount.DiscountValue)) throw new BusinessException("Unable to add discount code. DiscountValue is required"); code = CreateEventDiscountCode(context, discount); if (code.StartDate.HasValue && code.EndDate.HasValue && code.EndDate < code.StartDate) throw new BusinessException("Unable to add discount code. EndDate must be after StartDate"); if (theEvent.EventDiscountCodes.Any(c => c.DiscountCode.Code.ToUpper(CultureInfo.InvariantCulture) == code.Code.ToUpper(CultureInfo.InvariantCulture))) throw new BusinessException("Event discount codes must be unique"); discountCodes.AddObject(code); var codeWithId = discountCodes.FirstOrDefault(d => d.Code == code.Code); code.Id = codeWithId == null ? 0 : codeWithId.Id; } else { //If event discount code exists, update existing discount code UpdateExistingCode(context, code, discount); } } else { //If org unit discount code exists, just attach existing org unit code to event. //Org unit codes are not editable from the Event API. var codeWithId = discountCodes.FirstOrDefault(d => d.Code == code.Code); code.Id = codeWithId == null ? 0 : codeWithId.Id; } theEvent.EventDiscountCodes.Add(new EventDiscountCode { Event = theEvent, DiscountCode = code, DiscountCodeId = code.Id, }); } }
public static void SetDirectUrl(ObjectContext context, EventV2 source, Event theEvent) { //theEvent.DirectUrl is a Cleaned SEO string, do the same for the source directUrl var cleanedSourceDirectUrl = StringUtils.CleanupSeoString(source.DirectUrl); if (source.DirectUrl == null || string.Compare(theEvent.DirectUrl, cleanedSourceDirectUrl, CultureInfo.CurrentUICulture, CompareOptions.OrdinalIgnoreCase) == 0) return; theEvent.SetDirectUrl(source.DirectUrl); var eventsCheck = context.CreateObjectSet<Event>().Any(e => e.DirectUrl == theEvent.DirectUrl); if (eventsCheck) { throw new BusinessException("There is already an event with the DirectUrl of " + source.DirectUrl); } }
private static void BuildKeywordsWithInternalSynonymGenerator(Event theEvent, ISettingsManager settingsManager) { var newKeywords = BuildKeywordsWithSynonyms(settingsManager, theEvent.Keywords, _excludedWords); theEvent.Keywords = newKeywords; }
public void TestSetRegistrationDates() { var ev = new Event(); var occurrence = new EventOccurrence() { Event = ev }; occurrence.SetRegistrationDates(new DateTime(2000, 1, 1), new DateTime(2000, 1, 2)); Assert.AreEqual(occurrence.RegistrationStartDate, new DateTime(2000, 1, 1)); Assert.AreEqual(occurrence.RegistrationEndDate, new DateTime(2000, 1, 2)); }
public void TestCalculateCost_EarlyAbsolute() { var earlyCuttofDate = new DateTime(2000, 1, 1); var defaultCost = 10M; var earlyCost = 5M; var ev = new Event(); ev.Cost = defaultCost; var occurrence = new EventOccurrence() { Event = ev, Cost = defaultCost }; occurrence.AddOccurrenceDate(new DateTime(2000, 3, 1), new DateTime(2000, 3, 2)); var earlySchedule = new PricingSchedule(earlyCost, earlyCuttofDate); occurrence.SetEarlyRegistrationPrice(earlySchedule); occurrence.EnablePricingSchedule(); Assert.AreEqual(earlyCost, occurrence.CalculateCost(earlyCuttofDate.AddDays(-1))); Assert.AreEqual(earlyCost, occurrence.CalculateCost(earlyCuttofDate)); Assert.AreEqual(defaultCost, occurrence.CalculateCost(earlyCuttofDate.AddDays(1))); occurrence.DisablePricingSchedule(); Assert.AreEqual(defaultCost, occurrence.CalculateCost(earlyCuttofDate.AddDays(-1))); Assert.AreEqual(defaultCost, occurrence.CalculateCost(earlyCuttofDate)); Assert.AreEqual(defaultCost, occurrence.CalculateCost(earlyCuttofDate.AddDays(1))); }
public static void SetPaymentProcessorId(ObjectContext context, EventV2 source, Event theEvent) { if (source.PaymentProcessorConfigurationId == null) return; theEvent.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 == theEvent.PaymentProcessorConfigurationId); if (!payment) { throw new BusinessException("There was no Payment Processor Configurations found with the provided PaymentProcessorConfigurationId."); } }
public void TestIsEarlyAndLateAbsoluteMode_earlyRelative() { var ev = new Event(); var occurrence = new EventOccurrence() { Event = ev }; var earlySchedule = new PricingSchedule(10M, 30); occurrence.SetEarlyRegistrationPrice(earlySchedule); Assert.IsFalse(occurrence.IsEarlyAndLateAbsoluteMode); }
public void TestIsPublished_NoPublishDates() { var subject = new Event(); Assert.IsTrue(subject.IsPublishedAsOf(DateTime.Now)); }
public void TestSetTitle_tooLong() { var anEvent = new Event(); anEvent.SetTitle(new string('X', 501)); }
public void TestSetIsEnabled_withFutureEventOccurrenceEnabled() { var anEvent = new Event(); anEvent.Id = 1; anEvent.IsEnabled = true; var occurrence = new EventOccurrence(); occurrence.IsEnabled = true; occurrence.AddOccurrenceDate(DateTime.Now.AddDays(5), DateTime.Now.AddDays(6)); anEvent.EventOccurrences.Add(occurrence); var disabled = false; anEvent.SetIsEnabled(disabled); }
public static void SetEventType(ObjectContext context, EventV2 source, Event theEvent) { try { //ignore null values if (source.EventTypes == null) return; var types = context.CreateObjectSet<EventType>(); var eventTypes = new List<EventType>(); foreach (var typeName in source.EventTypes.Select(e => e.Name)) { var eventType = types.Where(i => i.Name == typeName).FirstOrDefault(); //Ensure eventType exists if (eventType == null) { //type doesn't exist, create a new type eventType = new EventType() { Name = typeName, IsEnabled = true }; types.AddObject(eventType); } eventTypes.Add(eventType); } UpdateEventType(theEvent, eventTypes, context); } catch (Exception ex) { throw new BusinessException("Error processing the event type for event '" + theEvent.Title + "' - " + ex.Message, ex); } }
public static void SetOrgUnitId(ObjectContext context, EventV2 source, Event theEvent) { if (source.OrgUnitId == null) return; theEvent.OrgUnitId = GetNullableInt(source.OrgUnitId); //being blank is ok, but do not need to check for orgUnit existence if (source.OrgUnitId.Length == 0) return; var orgUnits = context.CreateObjectSet<OrgUnit>().Any(o => o.Id == theEvent.OrgUnitId); if (!orgUnits) { throw new BusinessException("There was no orgUnit found with the provided OrgUnitId."); } }
public void TestSetRegistrationDates_StartEndSame() { var ev = new Event(); var occurrence = new EventOccurrence() { Event = ev }; occurrence.SetRegistrationDates(new DateTime(2000, 1, 1), new DateTime(2000, 1, 1)); }
private static DiscountCode FindOrgUnitDiscountCode(ObjectContext context, Event theEvent, DiscountCodeDtoV2 discount) { var discountCode = context.CreateObjectSet<OrgUnitDiscountCode>() .Where(o => o.DiscountCode.Code.ToUpper() == discount.Code.ToUpper()) .SingleOrDefault(); if (discountCode != null) { if (discountCode.OrgUnitId != theEvent.OrgUnitId.Value) throw new BusinessException("Discount code is associated with an org unit different from the event org unit."); return discountCode.DiscountCode; } else return null; }
public void TestSetIsEnabled_newEvent() { var anEvent = new Event(); anEvent.SetIsEnabled(true); Assert.AreEqual(anEvent.IsEnabled, true); }
public void TestSetDirectUrl_tooLong() { var anEvent = new Event(); anEvent.SetDirectUrl(new string('X', 256)); }
public void TestIsEarlyAndLateAbsoluteMode_lateAbsolute() { var ev = new Event(); var occurrence = new EventOccurrence() { Event = ev }; var lateSchedule = new PricingSchedule(10M, new DateTime(1999, 01, 01)); occurrence.SetLateRegistrationPrice(lateSchedule); Assert.IsTrue(occurrence.IsEarlyAndLateAbsoluteMode); }