Ejemplo n.º 1
0
        public static Schedule SyncSchedule(
            ESpace.Occurrence eSpaceOccurrence,
            EventItemOccurrence rockOccurrence,
            out bool changed
            )
        {
            changed = false;

            if (rockOccurrence.Schedule == null)
            {
                rockOccurrence.Schedule = new Schedule
                {
                    ForeignKey = ForeignKey_eSpaceOccurrenceId,
                    ForeignId  = eSpaceOccurrence.OccurrenceId.Value
                };
                changed = true;
            }

            var schedule = rockOccurrence.Schedule;


            if (schedule.EffectiveStartDate != eSpaceOccurrence.EventStart)
            {
                schedule.EffectiveStartDate = eSpaceOccurrence.EventStart;
                changed = true;
            }

            if (schedule.EffectiveEndDate != eSpaceOccurrence.EventEnd)
            {
                schedule.EffectiveEndDate = eSpaceOccurrence.EventEnd;
                changed = true;
            }

            var scheduleName = "";

            if (schedule.Name != scheduleName)
            {
                schedule.Name = scheduleName;
                changed       = true;
            }

            var iCalEvent = SyncICalEvent(eSpaceOccurrence, schedule, out var iCalChanged);

            if (iCalChanged)
            {
                // Serialize the event
                var calendar = new DDay.iCal.iCalendar();
                calendar.Events.Add(iCalEvent);
                var serializer = new DDay.iCal.Serialization.iCalendar.iCalendarSerializer(calendar);
                schedule.iCalendarContent = serializer.SerializeToString(calendar);
                changed = true;
            }

            return(schedule);
        }
Ejemplo n.º 2
0
        public static DDay.iCal.Event SyncICalEvent(
            ESpace.Occurrence eSpaceOccurrence,
            Schedule rockSchedule,
            out bool changed
            )
        {
            changed = false;

            var iCalEvent = rockSchedule.GetCalendarEvent();

            if (iCalEvent == null)
            {
                iCalEvent = new DDay.iCal.Event();
                changed   = true;
            }

            // Check for any recurrence dates
            if (iCalEvent.RecurrenceDates.Any())
            {
                iCalEvent.RecurrenceDates = null;
                changed = true;
            }

            // Check for any exception dates
            if (iCalEvent.ExceptionDates.Any())
            {
                iCalEvent.ExceptionDates = null;
                changed = true;
            }

            // Check for any recurrence rules
            if (iCalEvent.RecurrenceRules.Any())
            {
                iCalEvent.RecurrenceRules = null;
                changed = true;
            }

            // Check for any exception rules
            if (iCalEvent.ExceptionRules.Any())
            {
                iCalEvent.ExceptionRules = null;
                changed = true;
            }

            // Update the start date
            if (eSpaceOccurrence.EventStart.HasValue)
            {
                var startICalDate = new DDay.iCal.iCalDateTime(eSpaceOccurrence.EventStart.Value);
                if (iCalEvent.Start != startICalDate)
                {
                    iCalEvent.Start = startICalDate;
                    changed         = true;
                }
            }

            // Update the end date
            if (eSpaceOccurrence.EventEnd.HasValue)
            {
                var endICalDate = new DDay.iCal.iCalDateTime(eSpaceOccurrence.EventEnd.Value);
                if (iCalEvent.End != endICalDate)
                {
                    iCalEvent.End = endICalDate;
                    changed       = true;
                }
            }

            // Update IsAllDay
            var isAllDay = eSpaceOccurrence.IsAllDay ?? false;

            if (iCalEvent.IsAllDay != isAllDay)
            {
                iCalEvent.IsAllDay = isAllDay;
                changed            = true;
            }

            return(iCalEvent);
        }
Ejemplo n.º 3
0
        public static EventItemOccurrence SyncOccurrence(
            ESpace.Event eSpaceEvent,
            ESpace.Occurrence eSpaceOccurrence,
            EventItem rockEvent,
            CampusCache campus,
            Person contactPerson,
            string occurrenceApprovedAttributeKey,
            out bool changed,
            out bool attributeChanged
            )
        {
            attributeChanged = false;
            changed          = false;

            // Get or create the linked Rock occurrence
            var rockOccurrence = rockEvent.EventItemOccurrences.FirstOrDefault(e =>
                                                                               e.ForeignKey == ForeignKey_eSpaceOccurrenceId &&
                                                                               e.ForeignId == eSpaceOccurrence.OccurrenceId.Value &&
                                                                               e.CampusId == campus.Id
                                                                               );

            if (rockOccurrence == null)
            {
                rockOccurrence = new EventItemOccurrence {
                    ForeignKey = ForeignKey_eSpaceOccurrenceId,
                    ForeignId  = eSpaceOccurrence.OccurrenceId.Value,
                    CampusId   = campus.Id
                };
                rockEvent.EventItemOccurrences.Add(rockOccurrence);
                changed = true;
            }

            // Update the linked Contact Person
            if (rockOccurrence.ContactPersonAliasId != contactPerson?.PrimaryAliasId)
            {
                rockOccurrence.ContactPersonAliasId = contactPerson?.PrimaryAliasId;
                changed = true;
            }

            // Get the contact data
            var eventContact = eSpaceEvent.Contacts.FirstOrDefault();

            // Update the Contact Email
            var eventContactEmail = eventContact?.Email ?? "";

            if (rockOccurrence.ContactEmail != eventContactEmail)
            {
                rockOccurrence.ContactEmail = eventContactEmail;
                changed = true;
            }

            // Update the Contact Phone
            var eventContactPhone = PhoneNumber.FormattedNumber(null, eventContact?.Phone, false);

            if (rockOccurrence.ContactPhone != eventContactPhone)
            {
                rockOccurrence.ContactPhone = eventContactPhone;
                changed = true;
            }

            // Update the event location
            var eventLocation = eSpaceEvent.OffsiteLocation ?? "";

            if (rockOccurrence.Location != eventLocation)
            {
                rockOccurrence.Location = eventLocation;
                changed = true;
            }

            // Sync the schedule
            SyncSchedule(eSpaceOccurrence, rockOccurrence, out var scheduleChanged);
            changed = changed || scheduleChanged;

            // Check the approved attribute
            if (!string.IsNullOrEmpty(occurrenceApprovedAttributeKey))
            {
                rockOccurrence.LoadAttributes();

                var eSpaceApprovedValue = eSpaceOccurrence.OccurrenceStatus == ESpaceStatus_Approved ? "Approved" : "";
                var rockApprovedValue   = rockOccurrence.GetAttributeValue(occurrenceApprovedAttributeKey);
                if (rockApprovedValue != eSpaceApprovedValue)
                {
                    rockOccurrence.SetAttributeValue(occurrenceApprovedAttributeKey, eSpaceApprovedValue);
                    attributeChanged = true;
                }
            }

            return(rockOccurrence);
        }