Ejemplo n.º 1
0
        /// <summary>
        /// Binds the Attendance Occurrences ( Which shows the Location for the Attendance Occurrence for the selected Group + DateTime + Location ).
        /// groupScheduler.js will populate these with the scheduled resources
        /// </summary>
        private void BindAttendanceOccurrences()
        {
            var occurrenceSundayDate          = hfOccurrenceSundayDate.Value.AsDateTime().Value.Date;
            var occurrenceSundayWeekStartDate = occurrenceSundayDate.AddDays(-6);

            // make sure we don't let them schedule dates in the past
            if (occurrenceSundayWeekStartDate <= RockDateTime.Today)
            {
                occurrenceSundayWeekStartDate = RockDateTime.Today;
            }

            var scheduleId = rblSchedule.SelectedValueAsId();

            var rockContext        = new RockContext();
            var occurrenceSchedule = new ScheduleService(rockContext).GetNoTracking(scheduleId ?? 0);

            if (occurrenceSchedule == null)
            {
                btnAutoSchedule.Visible = false;
                return;
            }

            // get all the occurrences for the selected week for this scheduled (It could be more than once a week if it is a daily scheduled, or it might not be in the selected week if it is every 2 weeks, etc)
            var scheduleOccurrenceDateTimeList = occurrenceSchedule.GetScheduledStartTimes(occurrenceSundayWeekStartDate, occurrenceSundayDate.AddDays(1));

            if (!scheduleOccurrenceDateTimeList.Any())
            {
                btnAutoSchedule.Visible = false;
                return;
            }

            var occurrenceDateList = scheduleOccurrenceDateTimeList.Select(a => a.Date).ToList();

            btnAutoSchedule.Visible = true;

            var attendanceOccurrenceService = new AttendanceOccurrenceService(rockContext);
            var selectedGroupLocationIds    = cblGroupLocations.SelectedValuesAsInt;

            List <AttendanceOccurrence> missingAttendanceOccurrenceList = attendanceOccurrenceService.CreateMissingAttendanceOccurrences(occurrenceDateList, scheduleId.Value, selectedGroupLocationIds);

            if (missingAttendanceOccurrenceList.Any())
            {
                attendanceOccurrenceService.AddRange(missingAttendanceOccurrenceList);
                rockContext.SaveChanges();
            }

            IQueryable <AttendanceOccurrenceService.AttendanceOccurrenceGroupLocationScheduleConfigJoinResult> attendanceOccurrenceGroupLocationScheduleConfigQuery = attendanceOccurrenceService.AttendanceOccurrenceGroupLocationScheduleConfigJoinQuery(occurrenceDateList, scheduleId.Value, selectedGroupLocationIds);

            var attendanceOccurrencesList = attendanceOccurrenceGroupLocationScheduleConfigQuery.AsNoTracking()
                                            .OrderBy(a => a.GroupLocation.Order).ThenBy(a => a.GroupLocation.Location.Name)
                                            .Select(a => new AttendanceOccurrenceRowItem
            {
                LocationName           = a.AttendanceOccurrence.Location.Name,
                GroupLocationOrder     = a.GroupLocation.Order,
                LocationId             = a.AttendanceOccurrence.LocationId,
                Schedule               = a.AttendanceOccurrence.Schedule,
                OccurrenceDate         = a.AttendanceOccurrence.OccurrenceDate,
                AttendanceOccurrenceId = a.AttendanceOccurrence.Id,
                CapacityInfo           = new CapacityInfo
                {
                    MinimumCapacity = a.GroupLocationScheduleConfig.MinimumCapacity,
                    DesiredCapacity = a.GroupLocationScheduleConfig.DesiredCapacity,
                    MaximumCapacity = a.GroupLocationScheduleConfig.MaximumCapacity
                }
            }).ToList();

            var groupId = hfGroupId.Value.AsInteger();

            var attendanceOccurrencesOrderedList = attendanceOccurrencesList.OrderBy(a => a.ScheduledDateTime).ThenBy(a => a.GroupLocationOrder).ThenBy(a => a.LocationName).ToList();

            // if there are any people that signed up with no location preference, add the to a special list of "No Location Preference" occurrences to the top of the list
            var unassignedLocationOccurrenceList = attendanceOccurrenceService.Queryable()
                                                   .Where(a => occurrenceDateList.Contains(a.OccurrenceDate) && a.ScheduleId == scheduleId.Value && a.GroupId == groupId && a.LocationId.HasValue == false)
                                                   .Where(a => a.Attendees.Any(x => x.RequestedToAttend == true || x.ScheduledToAttend == true))
                                                   .Select(a => new AttendanceOccurrenceRowItem
            {
                LocationName           = "No Location Preference",
                GroupLocationOrder     = 0,
                LocationId             = null,
                Schedule               = a.Schedule,
                OccurrenceDate         = a.OccurrenceDate,
                AttendanceOccurrenceId = a.Id,
                CapacityInfo           = new CapacityInfo()
            })
                                                   .ToList()
                                                   .OrderBy(a => a.ScheduledDateTime)
                                                   .ToList();


            attendanceOccurrencesOrderedList.InsertRange(0, unassignedLocationOccurrenceList);

            rptAttendanceOccurrences.DataSource = attendanceOccurrencesOrderedList;
            rptAttendanceOccurrences.DataBind();

            hfDisplayedOccurrenceIds.Value = attendanceOccurrencesOrderedList.Select(a => a.AttendanceOccurrenceId).ToList().AsDelimited(",");
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Binds the Attendance Occurrences ( Which shows the Location for the Attendance Occurrence for the selected Group + DateTime + Location ).
        /// groupScheduler.js will populate these with the scheduled resources
        /// </summary>
        private void BindAttendanceOccurrences()
        {
            var occurrenceSundayDate          = hfOccurrenceSundayDate.Value.AsDateTime().Value.Date;
            var occurrenceSundayWeekStartDate = occurrenceSundayDate.AddDays(-6);

            var scheduleId = rblSchedule.SelectedValueAsId();

            var rockContext        = new RockContext();
            var occurrenceSchedule = new ScheduleService(rockContext).GetNoTracking(scheduleId ?? 0);

            if (occurrenceSchedule == null)
            {
                btnAutoSchedule.Visible = false;
                return;
            }

            var scheduleOccurrenceDateTime = occurrenceSchedule.GetNextStartDateTime(occurrenceSundayWeekStartDate);

            if (scheduleOccurrenceDateTime == null)
            {
                btnAutoSchedule.Visible = false;
                return;
            }

            var occurrenceDate = scheduleOccurrenceDateTime.Value.Date;

            btnAutoSchedule.Visible = true;

            var attendanceOccurrenceService = new AttendanceOccurrenceService(rockContext);
            var selectedGroupLocationIds    = cblGroupLocations.SelectedValuesAsInt;

            var missingAttendanceOccurrences = attendanceOccurrenceService.CreateMissingAttendanceOccurrences(occurrenceDate, scheduleId.Value, selectedGroupLocationIds);

            if (missingAttendanceOccurrences.Any())
            {
                attendanceOccurrenceService.AddRange(missingAttendanceOccurrences);
                rockContext.SaveChanges();
            }

            var attendanceOccurrenceGroupLocationScheduleConfigQuery = attendanceOccurrenceService.AttendanceOccurrenceGroupLocationScheduleConfigJoinQuery(occurrenceDate, scheduleId.Value, selectedGroupLocationIds);

            var attendanceOccurrencesOrderedList = attendanceOccurrenceGroupLocationScheduleConfigQuery.AsNoTracking()
                                                   .OrderBy(a => a.GroupLocation.Order).ThenBy(a => a.GroupLocation.Location.Name)
                                                   .Select(a => new AttendanceOccurrenceRowItem
            {
                LocationName           = a.AttendanceOccurrence.Location.Name,
                LocationId             = a.AttendanceOccurrence.LocationId,
                AttendanceOccurrenceId = a.AttendanceOccurrence.Id,
                CapacityInfo           = new CapacityInfo
                {
                    MinimumCapacity = a.GroupLocationScheduleConfig.MinimumCapacity,
                    DesiredCapacity = a.GroupLocationScheduleConfig.DesiredCapacity,
                    MaximumCapacity = a.GroupLocationScheduleConfig.MaximumCapacity
                }
            }).ToList();

            var groupId = hfGroupId.Value.AsInteger();

            var unassignedLocationOccurrence = attendanceOccurrenceService.Queryable()
                                               .Where(a => a.OccurrenceDate == occurrenceDate && a.ScheduleId == scheduleId.Value && a.GroupId == groupId && a.LocationId.HasValue == false)
                                               .Where(a => a.Attendees.Any(x => x.RequestedToAttend == true || x.ScheduledToAttend == true))
                                               .FirstOrDefault();

            if (unassignedLocationOccurrence != null)
            {
                attendanceOccurrencesOrderedList.Insert(0, new AttendanceOccurrenceRowItem
                {
                    LocationName           = "(Not Specified)",
                    LocationId             = null,
                    AttendanceOccurrenceId = unassignedLocationOccurrence.Id,
                    CapacityInfo           = new CapacityInfo()
                });
            }

            rptAttendanceOccurrences.DataSource = attendanceOccurrencesOrderedList;
            rptAttendanceOccurrences.DataBind();

            hfDisplayedOccurrenceIds.Value = attendanceOccurrencesOrderedList.Select(a => a.AttendanceOccurrenceId).ToList().AsDelimited(",");
        }