/// <summary> /// Grabs the necessary parameters from the XML and then calls the CreateAttendance() method /// to generate all the attendance data for the family. /// </summary> /// <param name="family">The family.</param> /// <param name="elemFamily">The elem family.</param> /// <param name="rockContext">The rock context.</param> /// <param name="attendanceData">The attendance data.</param> private void AddFamilyAttendance( Group family, XElement elemFamily, RockContext rockContext, Dictionary<Guid, List<Attendance>> attendanceData ) { // return from here if there's not startingAttendance date if ( elemFamily.Attribute( "startingAttendance" ) == null ) { return; } // get some variables we'll need to create the attendance records DateTime startingDate = DateTime.Parse( elemFamily.Attribute( "startingAttendance" ).Value.Trim(), new CultureInfo( "en-US" ) ); DateTime endDate = RockDateTime.Now; // If the XML specifies an endingAttendance date use it, otherwise use endingAttendanceWeeksAgo // to calculate the end date otherwise we'll just use the current date as the end date. if ( elemFamily.Attribute( "endingAttendance" ) != null ) { DateTime.TryParse( elemFamily.Attribute( "endingAttendance" ).Value.Trim(), out endDate ); } else if ( elemFamily.Attribute( "endingAttendanceWeeksAgo" ) != null ) { int endingWeeksAgo = 0; int.TryParse( elemFamily.Attribute( "endingAttendanceWeeksAgo" ).Value.Trim(), out endingWeeksAgo ); endDate = RockDateTime.Now.AddDays( -7 * endingWeeksAgo ); } int pctAttendance = 100; if ( elemFamily.Attribute( "percentAttendance" ) != null ) { int.TryParse( elemFamily.Attribute( "percentAttendance" ).Value.Trim(), out pctAttendance ); } int pctAttendedRegularService = 100; if ( elemFamily.Attribute( "percentAttendedRegularService" ) != null ) { int.TryParse( elemFamily.Attribute( "percentAttendedRegularService" ).Value.Trim(), out pctAttendedRegularService ); } int scheduleId = 13; if ( elemFamily.Attribute( "attendingScheduleId" ) != null ) { int.TryParse( elemFamily.Attribute( "attendingScheduleId" ).Value.Trim(), out scheduleId ); if ( !_scheduleTimes.ContainsKey( scheduleId ) ) { Schedule schedule = new ScheduleService( rockContext ).Get( scheduleId ); if ( schedule == null ) { // We're not going to continue if they are missing this schedule return; } _scheduleTimes.Add( scheduleId, schedule.GetCalenderEvent().DTStart.Value ); } } int altScheduleId = 4; if ( elemFamily.Attribute( "attendingAltScheduleId" ) != null ) { int.TryParse( elemFamily.Attribute( "attendingAltScheduleId" ).Value.Trim(), out altScheduleId ); if ( !_scheduleTimes.ContainsKey( altScheduleId ) ) { Schedule schedule = new ScheduleService( rockContext ).Get( altScheduleId ); if ( schedule == null ) { // We're not going to continue if they are missing this schedule return; } _scheduleTimes.Add( altScheduleId, schedule.GetCalenderEvent().DTStart.Value ); } } CreateAttendance( family.Members, startingDate, endDate, pctAttendance, pctAttendedRegularService, scheduleId, altScheduleId, attendanceData ); }