private void RunRockCleanupTaskUpdateEventNextOccurrenceDatesAndVerify(DateTime referenceDate)
        {
            // Execute the process to update the Event Occurrence next dates.
            var rockContext = new RockContext();

            Rock.Jobs.RockCleanup.UpdateEventNextOccurrenceDates(rockContext, referenceDate);

            // Verify the results of the cleanup.
            rockContext = new RockContext();

            var eventOccurrenceService = new EventItemOccurrenceService(rockContext);

            // Event 1.1 should be updated to the next occurrence after the reference date.
            var event11 = eventOccurrenceService.Get(testEventOccurrence11Guid);

            Assert.AreEqual(event11.NextStartDateTime, event11.Schedule.GetNextStartDateTime(referenceDate));

            // Event 1.2 should be updated to the next occurrence after the reference date.
            var event12 = eventOccurrenceService.Get(testEventOccurrence12Guid);

            Assert.AreEqual(event12.NextStartDateTime, event12.Schedule.GetNextStartDateTime(referenceDate));

            // Event 1.3 should be set to null because the schedule is inactive.
            var event13 = eventOccurrenceService.Get(testEventOccurrence13Guid);

            Assert.IsNull(event13.NextStartDateTime);

            // Event 2.1 should be set to null because the Event is inactive.
            var event21 = eventOccurrenceService.Get(testEventOccurrence21Guid);

            Assert.IsNull(event21.NextStartDateTime);
        }
Beispiel #2
0
        private EventItemOccurrence EventItemOccurrenceAddOrUpdateInstance(RockContext rockContext, Guid scheduleGuid, bool deleteExistingInstance)
        {
            // Get existing schedules.
            var scheduleService = new ScheduleService(rockContext);
            var schedule        = scheduleService.Get(scheduleGuid);

            // Get Event "Rock Solid Finances".
            var eventItemService           = new EventItemService(rockContext);
            var eventItemOccurrenceService = new EventItemOccurrenceService(rockContext);

            var financeEvent = eventItemService.Get(EventFinancesClassGuid.AsGuid());

            // Add a new occurrence of this event.
            var financeEvent1 = eventItemOccurrenceService.Get(FinancesClassOccurrenceTestGuid.AsGuid());

            if (financeEvent1 != null && deleteExistingInstance)
            {
                eventItemOccurrenceService.Delete(financeEvent1);
                rockContext.SaveChanges();
            }
            financeEvent1 = new EventItemOccurrence();

            var mainCampusId = CampusCache.GetId(MainCampusGuidString.AsGuid());

            financeEvent1.Location   = "Meeting Room 1";
            financeEvent1.ForeignKey = TestDataForeignKey;
            financeEvent1.ScheduleId = schedule.Id;
            financeEvent1.Guid       = FinancesClassOccurrenceTestGuid.AsGuid();
            financeEvent1.CampusId   = mainCampusId;

            financeEvent.EventItemOccurrences.Add(financeEvent1);

            return(financeEvent1);
        }
 /// <summary>
 /// Handles the RowSelected event of the gCalendarItemOccurrenceList control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="RowEventArgs"/> instance containing the event data.</param>
 protected void gCalendarItemOccurrenceList_RowSelected(object sender, RowEventArgs e)
 {
     using (RockContext rockContext = new RockContext())
     {
         EventItemOccurrenceService eventItemOccurrenceService = new EventItemOccurrenceService(rockContext);
         EventItemOccurrence        eventItemOccurrence        = eventItemOccurrenceService.Get(e.RowKeyId);
         if (eventItemOccurrence != null)
         {
             var qryParams = new Dictionary <string, string>();
             qryParams.Add("EventCalendarId", PageParameter("EventCalendarId"));
             qryParams.Add("EventItemId", _eventItem.Id.ToString());
             qryParams.Add("EventItemOccurrenceId", eventItemOccurrence.Id.ToString());
             NavigateToLinkedPage("DetailPage", qryParams);
         }
     }
 }
        /// <summary>
        /// Handles the Delete event of the gCalendarItemOccurrenceList control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RowEventArgs"/> instance containing the event data.</param>
        protected void gCalendarItemOccurrenceList_Delete(object sender, RowEventArgs e)
        {
            using (RockContext rockContext = new RockContext())
            {
                EventItemOccurrenceService eventItemOccurrenceService = new EventItemOccurrenceService(rockContext);
                EventItemOccurrence        eventItemOccurrence        = eventItemOccurrenceService.Get(e.RowKeyId);
                if (eventItemOccurrence != null)
                {
                    string errorMessage;
                    if (!eventItemOccurrenceService.CanDelete(eventItemOccurrence, out errorMessage))
                    {
                        mdGridWarning.Show(errorMessage, ModalAlertType.Information);
                        return;
                    }

                    eventItemOccurrenceService.Delete(eventItemOccurrence);
                    rockContext.SaveChanges();
                }
            }

            BindCampusGrid();
        }
Beispiel #5
0
        /// <summary>
        /// Handles the Click event of the btnDelete control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            using (var rockContext = new RockContext())
            {
                EventItemOccurrenceService eventItemOccurrenceService = new EventItemOccurrenceService(rockContext);
                EventItemOccurrence        eventItemOccurrence        = eventItemOccurrenceService.Get(hfEventItemOccurrenceId.Value.AsInteger());

                if (eventItemOccurrence != null)
                {
                    string errorMessage;
                    if (!eventItemOccurrenceService.CanDelete(eventItemOccurrence, out errorMessage))
                    {
                        mdDeleteWarning.Show(errorMessage, ModalAlertType.Information);
                        return;
                    }

                    eventItemOccurrenceService.Delete(eventItemOccurrence);

                    rockContext.SaveChanges();
                }
            }

            NavigateToParentPage();
        }
        /// <summary>
        /// Handles the Click event of the btnDelete control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void btnDelete_Click( object sender, EventArgs e )
        {
            using ( var rockContext = new RockContext() )
            {
                EventItemOccurrenceService eventItemOccurrenceService = new EventItemOccurrenceService( rockContext );
                EventItemOccurrence eventItemOccurrence = eventItemOccurrenceService.Get( hfEventItemOccurrenceId.Value.AsInteger() );

                if ( eventItemOccurrence != null )
                {
                    string errorMessage;
                    if ( !eventItemOccurrenceService.CanDelete( eventItemOccurrence, out errorMessage ) )
                    {
                        mdDeleteWarning.Show( errorMessage, ModalAlertType.Information );
                        return;
                    }

                    eventItemOccurrenceService.Delete( eventItemOccurrence );

                    rockContext.SaveChanges();
                }
            }

            NavigateToParentPage();
        }
        /// <summary>
        /// Modifies the Rock Solid Finances Class to add multiple schedules and campuses.
        /// </summary>
        private static void InitializeEventRockSolidFinancesClassTestData()
        {
            var rockContext = new RockContext();

            // Add a new campus
            var campusService = new CampusService(rockContext);

            var campus2 = campusService.Get(SecondaryCampusGuidString.AsGuid());

            if (campus2 == null)
            {
                campus2 = new Campus();

                campusService.Add(campus2);
            }

            campus2.Name = "Stepping Stone";
            campus2.Guid = SecondaryCampusGuidString.AsGuid();

            rockContext.SaveChanges();

            // Get existing schedules.
            var scheduleService = new ScheduleService(rockContext);

            var scheduleSat1630Id = scheduleService.GetId(ScheduleSat1630Guid.AsGuid());
            var scheduleSat1800Id = scheduleService.GetId(ScheduleSun1200Guid.AsGuid());

            // Get Event "Rock Solid Finances".
            var eventItemService           = new EventItemService(rockContext);
            var eventItemOccurrenceService = new EventItemOccurrenceService(rockContext);

            var financeEvent = eventItemService.Get(EventFinancesClassGuid.AsGuid());

            // Add an occurrence of this event for each Schedule.
            var financeEvent1 = eventItemOccurrenceService.Get(FinancesClassOccurrenceSat1630Guid.AsGuid());

            if (financeEvent1 == null)
            {
                financeEvent1 = new EventItemOccurrence();
            }

            var mainCampusId   = CampusCache.GetId(MainCampusGuidString.AsGuid());
            var secondCampusId = CampusCache.GetId(SecondaryCampusGuidString.AsGuid());

            financeEvent1.Location   = "Meeting Room 1";
            financeEvent1.ForeignKey = TestDataForeignKey;
            financeEvent1.ScheduleId = scheduleSat1630Id;
            financeEvent1.Guid       = FinancesClassOccurrenceSat1630Guid.AsGuid();
            financeEvent1.CampusId   = mainCampusId;

            financeEvent.EventItemOccurrences.Add(financeEvent1);

            var financeEvent2 = eventItemOccurrenceService.Get(FinancesClassOccurrenceSun1200Guid.AsGuid());

            if (financeEvent2 == null)
            {
                financeEvent2 = new EventItemOccurrence();
            }

            financeEvent2.Location   = "Meeting Room 2";
            financeEvent2.ForeignKey = TestDataForeignKey;
            financeEvent2.ScheduleId = scheduleSat1800Id;
            financeEvent2.Guid       = FinancesClassOccurrenceSun1200Guid.AsGuid();
            financeEvent2.CampusId   = secondCampusId;

            financeEvent.EventItemOccurrences.Add(financeEvent2);

            rockContext.SaveChanges();
        }
 /// <summary>
 /// Handles the Copy event of the gCalendarItemOccurrenceList control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="RowEventArgs"/> instance containing the event data.</param>
 protected void gCalendarItemOccurrenceList_Copy( object sender, RowEventArgs e )
 {
     using ( RockContext rockContext = new RockContext() )
     {
         EventItemOccurrenceService eventItemOccurrenceService = new EventItemOccurrenceService( rockContext );
         EventItemOccurrence eventItemOccurrence = eventItemOccurrenceService.Get( e.RowKeyId );
         if ( eventItemOccurrence != null )
         {
             var qryParams = new Dictionary<string, string>();
             qryParams.Add( "EventCalendarId", PageParameter( "EventCalendarId" ) );
             qryParams.Add( "EventItemId", _eventItem.Id.ToString() );
             qryParams.Add( "EventItemOccurrenceId", "0" );
             qryParams.Add( "CopyFromId", eventItemOccurrence.Id.ToString() );
             NavigateToLinkedPage( "DetailPage", qryParams );
         }
     }
 }
        /// <summary>
        /// Handles the Delete event of the gCalendarItemOccurrenceList control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RowEventArgs"/> instance containing the event data.</param>
        protected void gCalendarItemOccurrenceList_Delete( object sender, RowEventArgs e )
        {
            using ( RockContext rockContext = new RockContext() )
            {
                EventItemOccurrenceService eventItemOccurrenceService = new EventItemOccurrenceService( rockContext );
                EventItemOccurrence eventItemOccurrence = eventItemOccurrenceService.Get( e.RowKeyId );
                if ( eventItemOccurrence != null )
                {
                    string errorMessage;
                    if ( !eventItemOccurrenceService.CanDelete( eventItemOccurrence, out errorMessage ) )
                    {
                        mdGridWarning.Show( errorMessage, ModalAlertType.Information );
                        return;
                    }

                    eventItemOccurrenceService.Delete( eventItemOccurrence );
                    rockContext.SaveChanges();
                }
            }

            BindCampusGrid();
        }