Ejemplo n.º 1
0
        protected void gOccurrences_RowSelected(object sender, RowEventArgs e)
        {
            var accessKey  = ( string )e.RowKeyValue;
            var occurrence = OccurrenceCache.Get(accessKey);

            ShowAttendances(occurrence.Attendances.Select(a => a.Id).ToList());
        }
Ejemplo n.º 2
0
        private void ShowCheckinCompletion()
        {
            pnlQr.Visible          = false;
            pnlPostCheckin.Visible = true;
            ltPostCheckin.Text     = GetAttributeValue(AttributeKeys.PostCheckinInstructions);

            //This is all an elaborate effort to get the family's checkin data in an organized fashion without touching the db
            //The thought is I can add more webservers I can't add more database servers right now.

            var personIds = CurrentPerson.PrimaryFamily.Members.Select(m => m.Person)
                            .OrderBy(p => p.AgeClassification)
                            .ThenBy(p => p.BirthDate)
                            .Select(p => p.Id)
                            .ToList();

            var attendances = AttendanceCache.All()
                              .Where(a => personIds.Contains(a.PersonId) && a.AttendanceState != AttendanceState.CheckedOut)
                              .ToList();

            var scheduleIds = attendances.Select(a => a.ScheduleId).Distinct().ToList();

            var tokenOccurrences = OccurrenceCache.All() //Just need the schedule data so we can order stuff.
                                   .Where(o => scheduleIds.Contains(o.ScheduleId))
                                   .DistinctBy(o => o.ScheduleId)
                                   .OrderBy(o => o.ScheduleStartTime)
                                   .ToList();

            var attendanceData = new StringBuilder();

            foreach (var tokenOccurrence in tokenOccurrences)
            {
                if (attendances.Where(a => a.ScheduleId == tokenOccurrence.ScheduleId).Any())
                {
                    attendanceData.Append("<b>" + tokenOccurrence.ScheduleName + "</b><ul>");
                    foreach (var personId in personIds)
                    {
                        var attendance = attendances.FirstOrDefault(a => a.PersonId == personId && a.ScheduleId == tokenOccurrence.ScheduleId);
                        if (attendance == null)
                        {
                            continue;
                        }

                        OccurrenceCache occurrence = OccurrenceCache.Get(attendance.OccurrenceAccessKey);
                        if (occurrence == null)
                        {
                            continue;
                        }

                        attendanceData.Append(string.Format("<li>{0}: {1} in {2}</li>", attendance.PersonName, occurrence.GroupName, occurrence.LocationName));
                    }
                    attendanceData.Append("</ul>");
                }
            }

            ltAttendance.Text = attendanceData.ToString();
        }
        /// <summary>
        /// Executes the specified workflow.
        /// </summary>
        /// <param name="rockContext">The rock context.</param>
        /// <param name="action">The workflow action.</param>
        /// <param name="entity">The entity.</param>
        /// <param name="errorMessages">The error messages.</param>
        /// <returns></returns>
        /// <exception cref="System.NotImplementedException"></exception>
        public override bool Execute(RockContext rockContext, WorkflowAction action, object entity, out List <string> errorMessages)
        {
            var filterAttendanceSchedules = GetActionAttributeValue(action, "FilterAttendanceSchedules").AsBoolean();

            var checkInState = GetCheckInState(entity, out errorMessages);

            if (checkInState != null)
            {
                var family = checkInState.CheckIn.Families.Where(f => f.Selected).FirstOrDefault();
                if (family != null)
                {
                    foreach (var person in family.People)
                    {
                        var inScheduleIds = AttendanceCache.All()
                                            .Where(a => a.PersonId == person.Person.Id &&
                                                   a.AttendanceState != AttendanceState.CheckedOut)
                                            .Select(a => a.ScheduleId)
                                            .ToList();

                        foreach (var groupType in person.GroupTypes)
                        {
                            foreach (var group in groupType.Groups)
                            {
                                foreach (var location in group.Locations)
                                {
                                    foreach (var schedule in location.Schedules.ToList())
                                    {
                                        if (filterAttendanceSchedules && inScheduleIds.Contains(schedule.Schedule.Id))
                                        {
                                            location.Schedules.Remove(schedule);
                                            continue;
                                        }

                                        var occurrence = OccurrenceCache.Get(group.Group.Id, location.Location.Id, schedule.Schedule.Id);
                                        if (occurrence == null || occurrence.IsFull)
                                        {
                                            location.Schedules.Remove(schedule);
                                            continue;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    return(true);
                }
                else
                {
                    errorMessages.Add("There is not a family that is selected");
                }

                return(false);
            }
            errorMessages.Add($"Attempted to run {this.GetType().GetFriendlyTypeName()} in check-in, but the check-in state was null.");
            return(false);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Executes the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        public void Execute(IJobExecutionContext context)
        {
            JobDataMap dataMap = context.JobDetail.JobDataMap;

            var rockContext = new RockContext();

            var definedTypeService   = new DefinedTypeService(rockContext);
            var definedValueService  = new DefinedValueService(rockContext);
            var dtDeactivated        = definedTypeService.Get(Constants.DEFINED_TYPE_DISABLED_GROUPLOCATIONSCHEDULES.AsGuid());
            var dvDeactivated        = dtDeactivated.DefinedValues.ToList();
            var scheduleService      = new ScheduleService(rockContext);
            var groupLocationService = new GroupLocationService(rockContext);
            var deactivatedGroupLocationSchedules = dvDeactivated.Select(dv => dv.Value.Split('|'))
                                                    .Select(s => new
            {
                GroupLocation = groupLocationService.Get(s[0].AsInteger()),
                Schedule      = scheduleService.Get(s[1].AsInteger()),
            }).ToList();

            //add schedules back
            foreach (var groupLocationSchedule in deactivatedGroupLocationSchedules)
            {
                if (!groupLocationSchedule.GroupLocation.Schedules.Contains(groupLocationSchedule.Schedule))
                {
                    groupLocationSchedule.GroupLocation.Schedules.Add(groupLocationSchedule.Schedule);
                }
            }
            //Remove defined values
            foreach (var value in dvDeactivated)
            {
                definedValueService.Delete(value);
                Rock.Web.Cache.DefinedValueCache.Remove(value.Id);
            }

            //clear defined type cache
            Rock.Web.Cache.DefinedTypeCache.Remove(dtDeactivated.Id);

            rockContext.SaveChanges();

            //clear caches
            KioskTypeCache.Clear();
            Rock.CheckIn.KioskDevice.Clear();
            OccurrenceCache.Clear();
            AttendanceCache.Clear();

            context.Result = string.Format("Finished at {0}. Reset {1} GroupScheduleLocations.", Rock.RockDateTime.Now, deactivatedGroupLocationSchedules.Count);
        }
Ejemplo n.º 5
0
        protected void btnOccurrences_Click(object sender, EventArgs e)
        {
            btnOccurrences.CssClass   = activeCss;
            btnAttendances.CssClass   = defaultCss;
            btnMobileRecords.CssClass = defaultCss;
            btnKioskTypes.CssClass    = defaultCss;
            pnlOccurrences.Visible    = true;
            pnlAttendances.Visible    = false;
            pnlMobileRecords.Visible  = false;
            pnlKioskTypes.Visible     = false;
            pnlVerify.Visible         = false;

            var occurrences = OccurrenceCache.All().Select(o => new CacheContainer(o, o.AccessKey)).ToList();

            gOccurrences.DataSource = occurrences;
            gOccurrences.DataBind();
        }
Ejemplo n.º 6
0
        internal static AttendanceOccurrence GetOccurrenceForLocation(RockContext rockContext, Location location)
        {
            if (IsSubRoom(location))
            {
                location = location.ParentLocation;
            }

            AttendanceOccurrenceService attendanceOccurrenceService = new AttendanceOccurrenceService(rockContext);
            var occurrences = attendanceOccurrenceService.Queryable()
                              .Where(o => o.OccurrenceDate == RockDateTime.Now.Date && o.LocationId == location.Id).ToList();
            var volunteerOccurrences = occurrences.Where(o => OccurrenceCache.GetVolunteerOccurrences().Select(oc => oc.GroupId).Contains(o.GroupId ?? 0)).FirstOrDefault();

            if (volunteerOccurrences != null)
            {
                return(volunteerOccurrences);
            }
            return(null);
        }
Ejemplo n.º 7
0
        private void VerifyCache()
        {
            List <string> errors = new List <string>();

            KioskTypeCache.Verify(ref errors);
            AttendanceCache.Verify(ref errors);
            MobileCheckinRecordCache.Verify(ref errors);
            OccurrenceCache.Verify(ref errors);

            if (errors.Any())
            {
                ltVerify.Text = string.Join("<br>", errors);
            }
            else
            {
                ltVerify.Text = "<b>No Errors</b>";
            }
        }
Ejemplo n.º 8
0
        private void BindGrid()
        {
            gReport.Visible        = false;
            nbNotification.Visible = false;
            RockContext rockContext = new RockContext();
            AttendanceOccurrenceService attendanceOccurrenceService = new AttendanceOccurrenceService(rockContext);
            AttendanceService           attendanceService           = new AttendanceService(rockContext);
            LocationService             locationService             = new LocationService(rockContext);
            ScheduleService             scheduleService             = new ScheduleService(rockContext);

            var location = lpLocation.Location;

            if (location == null || dpDate.SelectedDate == null)
            {
                return;
            }

            //Set the name of the export
            List <string> locationNameList  = new List <string>();
            var           locationForExport = location;

            while (true)
            {
                if (locationForExport == null)
                {
                    break;
                }
                locationNameList.Add(locationForExport.Name);
                locationForExport = locationForExport.ParentLocation;
            }

            locationNameList.Reverse();
            gReport.ExportTitleName = dpDate.SelectedDate.Value.ToString("MM/dd/yyyy") +
                                      "  -- ";

            if (tgChildLocations.Checked)
            {
                gReport.ExportTitleName += " Child Locations of: ";
            }
            gReport.ExportTitleName += string.Join(" > ", locationNameList);
            var schedule = scheduleService.Get(spSchedule.SelectedValueAsId() ?? 0);

            if (schedule != null)
            {
                gReport.ExportTitleName += " (" + schedule.Name + ")";
            }

            var fileName = dpDate.SelectedDate.Value.ToString("MM.dd.yyyy") +
                           (tgChildLocations.Checked ? "_ChildLocationsOf_" : "_") +
                           location.Name;

            if (schedule != null)
            {
                fileName += "_" + schedule.Name;
            }

            gReport.ExportFilename = fileName;



            //Get child locations if needed
            var locationIds = new List <int> {
                location.Id
            };

            if (tgChildLocations.Checked)
            {
                List <Location> childLocations = GetChildLocations(location);
                locationIds.AddRange(childLocations.Select(l => l.Id));
            }

            var attendanceOccurrencesQry = attendanceOccurrenceService
                                           .Queryable()
                                           .Where(ao => ao.OccurrenceDate == (dpDate.SelectedDate ?? RockDateTime.Now))
                                           .Where(ao => locationIds.Contains(ao.LocationId ?? 0))
                                           .Where(ao => ao.Group != null && ao.Schedule != null);


            var scheduleId = spSchedule.SelectedValueAsId();

            if (scheduleId != null)
            {
                attendanceOccurrencesQry = attendanceOccurrencesQry.Where(ao => ao.ScheduleId == scheduleId);
            }

            var attendanceOccurrences = attendanceOccurrencesQry
                                        .Select(ao => ao.Id)
                                        .ToList();

            var attendances = attendanceService.Queryable("PersonAlias, PersonAlias.Person, Occurrence, Occurrence.Group, Occurrence.Location, Occurrence.Schedule, Device")
                              .Where(a => attendanceOccurrences.Contains(a.OccurrenceId))
                              .ToList();

            if (!attendances.Any())
            {
                nbNotification.Visible = true;
                nbNotification.Text    = "Could not find any attendances with these parameters";
                return;
            }

            var records           = new List <AttendanceRecord>();
            var volunteerGroupIds = OccurrenceCache.GetVolunteerOccurrences().Select(o => o.GroupId).ToList();

            foreach (var attendance in attendances)
            {
                var record = new AttendanceRecord
                {
                    PersonId    = attendance.PersonAlias.Person.Id,
                    PersonName  = attendance.PersonAlias.Person.FullNameReversed,
                    Age         = attendance.PersonAlias.Person.Age,
                    Schedule    = attendance.Occurrence.Schedule.Name,
                    Location    = attendance.Occurrence.Location.Name,
                    Group       = attendance.Occurrence.Group.Name,
                    CheckInTime = attendance.CreatedDateTime,
                    EntryTime   = attendance.StartDateTime,
                    ExitTime    = attendance.EndDateTime,
                    DidAttend   = attendance.DidAttend,
                    IsVolunteer = volunteerGroupIds.Contains(attendance.Occurrence.GroupId ?? 0),
                    Device      = attendance.Device != null ? attendance.Device.Name : "Room Scanner"
                };

                if (attendance.ForeignId != null)
                {
                    var subLocation = locationService.Get(attendance.ForeignId ?? 0);
                    if (subLocation != null)
                    {
                        record.SubLocation = subLocation.Name;
                    }
                }

                if (record.CheckInTime >= record.EntryTime && record.Device != "Room Scanner")
                {
                    record.EntryTime = null;
                }

                records.Add(record);
            }

            records = records
                      .OrderBy(r => r.CheckInTime)
                      .ToList();

            gReport.Visible    = true;
            gReport.DataSource = records;
            gReport.DataBind();
        }