Beispiel #1
0
 private static void CheckEventRequiredFields(EventV2 currentEvent)
 {
     if (string.IsNullOrEmpty(currentEvent.Title))
         throw new InvalidOperationException("Event Title is required.");
     if (string.IsNullOrEmpty(currentEvent.DirectUrl))
         throw new InvalidOperationException("Event DirectUrl is required.");
     if (string.IsNullOrEmpty(currentEvent.SummaryDescription))
         throw new InvalidOperationException("Event SummaryDescription is required.");
     if (currentEvent.EventTopics == null || !currentEvent.EventTopics.Any())
         throw new InvalidOperationException("EventTopic is required.");
     if (currentEvent.EventTypes == null || !currentEvent.EventTypes.Any())
         throw new InvalidOperationException("EventType is required.");
 }
Beispiel #2
0
        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;
        }
Beispiel #3
0
        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
                    });
                }
            }
        }
Beispiel #4
0
        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.");
            }
        }
Beispiel #5
0
        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.");
            }
        }
Beispiel #6
0
        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);
            }
        }
Beispiel #7
0
        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);
        }
Beispiel #8
0
        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,
                });
            }
        }
Beispiel #9
0
        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);
            }
        }