/// <summary> /// Loads the move person schedules based on selected Group and Location /// </summary> /// <param name="selectedGroupId">The selected group identifier.</param> /// <param name="selectedLocationId">The selected location identifier.</param> private void LoadMovePersonSchedules(int?selectedGroupId, int?selectedLocationId) { var rockContext = new RockContext(); var attendanceService = new AttendanceService(rockContext); var scheduleService = new ScheduleService(rockContext); /* 12-7-2021 MDP * * There is special logic for populating the Schedule, Group and Location pickers and it isn't very intuitive. * Also, this logic could change based on feedback. If it does change, make sure to append this engineering note. * As of 12-7-2021, this is how it should work: * * - List All Checkin Locations * - List Groups associated with selected Location * - List schedules limited to selected Group and Location and * - Named schedule * - Active * - Not limited to Checkin Time * - Not limited to ones that have a CheckInStartOffsetMinutes specified. * - Not limited to only current day's schedules * - If Group is not selected, don't filter schedules by Group * - If Location is not selected, don't filter Groups by Location and don't filter Schedules by Location * */ var groupLocationQuery = new GroupLocationService(rockContext).Queryable(); if (selectedGroupId.HasValue) { groupLocationQuery = groupLocationQuery.Where(a => a.GroupId == selectedGroupId.Value); } if (selectedLocationId.HasValue) { groupLocationQuery = groupLocationQuery.Where(a => a.LocationId == selectedLocationId.Value); } var scheduleQry = scheduleService.Queryable().Where(a => a.IsActive && groupLocationQuery.Any(x => x.Schedules.Any(s => s.Id == a.Id)) && a.Name != null && a.Name != string.Empty).ToList(); var scheduleList = scheduleQry.ToList(); var sortedScheduleList = scheduleList.OrderByOrderAndNextScheduledDateTime(); ddlMovePersonSchedule.Items.Clear(); foreach (var schedule in sortedScheduleList) { ddlMovePersonSchedule.Items.Add(new ListItem(schedule.Name, schedule.Id.ToString())); } }
/// <summary> /// Creates a Linq Expression that can be applied to an IQueryable to filter the result set. /// </summary> /// <param name="entityType">The type of entity in the result set.</param> /// <param name="serviceInstance">A service instance that can be queried to obtain the result set.</param> /// <param name="parameterExpression">The input parameter that will be injected into the filter expression.</param> /// <param name="selection">A formatted string representing the filter settings.</param> /// <returns> /// A Linq Expression that can be used to filter an IQueryable. /// </returns> /// <exception cref="System.Exception">Filter issue(s): + errorMessages.AsDelimited( ; )</exception> public override Expression GetExpression(Type entityType, IService serviceInstance, ParameterExpression parameterExpression, string selection) { var settings = new FilterSettings(selection); var context = (RockContext)serviceInstance.Context; // Get the Location Data View that defines the set of candidates from which proximate Locations can be selected. var dataView = DataComponentSettingsHelper.GetDataViewForFilterComponent(settings.DataViewGuid, context); // Evaluate the Data View that defines the candidate Locations. var locationService = new LocationService(context); var locationQuery = locationService.Queryable(); if (dataView != null) { locationQuery = DataComponentSettingsHelper.FilterByDataView(locationQuery, dataView, locationService); } // Get all the Family Groups that have a Location matching one of the candidate Locations. int familyGroupTypeId = GroupTypeCache.Get(SystemGuid.GroupType.GROUPTYPE_FAMILY.AsGuid()).Id; var groupLocationsQuery = new GroupLocationService(context).Queryable() .Where(gl => gl.Group.GroupTypeId == familyGroupTypeId && locationQuery.Any(l => l.Id == gl.LocationId)); // If a Location Type is specified, apply the filter condition. if (settings.LocationTypeGuid.HasValue) { int groupLocationTypeId = DefinedValueCache.Get(settings.LocationTypeGuid.Value).Id; groupLocationsQuery = groupLocationsQuery.Where(x => x.GroupLocationTypeValue.Id == groupLocationTypeId); } // Get all of the Group Members of the qualifying Families. var groupMemberServiceQry = new GroupMemberService(context).Queryable() .Where(gm => groupLocationsQuery.Any(gl => gl.GroupId == gm.GroupId)); // Get all of the People corresponding to the qualifying Group Members. var qry = new PersonService(context).Queryable() .Where(p => groupMemberServiceQry.Any(gm => gm.PersonId == p.Id)); // Retrieve the Filter Expression. var extractedFilterExpression = FilterExpressionExtractor.Extract <Model.Person>(qry, parameterExpression, "p"); return(extractedFilterExpression); }
/// <summary> /// Creates a Linq Expression that can be applied to an IQueryable to filter the result set. /// </summary> /// <param name="entityType">The type of entity in the result set.</param> /// <param name="serviceInstance">A service instance that can be queried to obtain the result set.</param> /// <param name="parameterExpression">The input parameter that will be injected into the filter expression.</param> /// <param name="selection">A formatted string representing the filter settings.</param> /// <returns> /// A Linq Expression that can be used to filter an IQueryable. /// </returns> /// <exception cref="System.Exception">Filter issue(s): + errorMessages.AsDelimited( ; )</exception> public override Expression GetExpression(Type entityType, IService serviceInstance, ParameterExpression parameterExpression, string selection) { var settings = new FilterSettings(selection); var context = ( RockContext )serviceInstance.Context; var locationService = new LocationService(context); var locationQuery = locationService.Queryable(); if (locationQuery != null) { if (!string.IsNullOrWhiteSpace(settings.Street1)) { locationQuery = locationQuery.Where(l => l.Street1.Contains(settings.Street1)); } if (!string.IsNullOrWhiteSpace(settings.City)) { locationQuery = locationQuery.Where(l => l.City == settings.City); } if (!string.IsNullOrWhiteSpace(settings.State)) { locationQuery = locationQuery.Where(l => l.State == settings.State); } if (!string.IsNullOrWhiteSpace(settings.PostalCode)) { locationQuery = locationQuery.Where(l => l.PostalCode.StartsWith(settings.PostalCode)); } if (!string.IsNullOrWhiteSpace(settings.Country)) { locationQuery = locationQuery.Where(l => l.Country == settings.Country); } } // Get all the Family Groups that have a Location matching one of the candidate Locations. int familyGroupTypeId = GroupTypeCache.Read(Rock.SystemGuid.GroupType.GROUPTYPE_FAMILY.AsGuid()).Id; var groupLocationsQuery = new GroupLocationService(context).Queryable() .Where(gl => gl.Group.GroupTypeId == familyGroupTypeId && locationQuery.Any(l => l.Id == gl.LocationId)); // If a Location Type is specified, apply the filter condition. if (settings.LocationTypeGuid.HasValue) { int groupLocationTypeId = DefinedValueCache.Read(settings.LocationTypeGuid.Value).Id; groupLocationsQuery = groupLocationsQuery.Where(x => x.GroupLocationTypeValue.Id == groupLocationTypeId); } // Get all of the Group Members of the qualifying Families. var groupMemberServiceQry = new GroupMemberService(context).Queryable() .Where(gm => groupLocationsQuery.Any(gl => gl.GroupId == gm.GroupId)); // Get all of the People corresponding to the qualifying Group Members. var qry = new PersonService(context).Queryable() .Where(p => groupMemberServiceQry.Any(gm => gm.PersonId == p.Id)); // Retrieve the Filter Expression. var extractedFilterExpression = FilterExpressionExtractor.Extract <Rock.Model.Person>(qry, parameterExpression, "p"); return(extractedFilterExpression); }