/// <summary> /// Binds the grid. /// </summary> protected void BindGrid() { var groupLocationService = new GroupLocationService(); var groupLocationQry = groupLocationService.Queryable(); int groupTypeId = ddlGroupType.SelectedValueAsInt() ?? Rock.Constants.All.Id; if (groupTypeId != Rock.Constants.All.Id) { groupLocationQry = groupLocationQry.Where(a => a.Group.GroupTypeId == groupTypeId); } var qryList = groupLocationQry.Select(a => new { GroupLocationId = a.Id, GroupName = a.Group.Name, LocationName = a.Location.Name, ScheduleIdList = a.Schedules.Select(s => s.Id), a.LocationId }).ToList(); int parentLocationId = ddlParentLocation.SelectedValueAsInt() ?? Rock.Constants.All.Id; if (parentLocationId != Rock.Constants.All.Id) { var descendantLocationIds = new LocationService().GetAllDescendents(parentLocationId).Select(a => a.Id); qryList = qryList.Where(a => descendantLocationIds.Contains(a.LocationId)).ToList(); } // put stuff in a datatable so we can dynamically have columns for each Schedule DataTable dataTable = new DataTable(); dataTable.Columns.Add("GroupLocationId"); dataTable.Columns.Add("GroupName"); dataTable.Columns.Add("LocationName"); foreach (var field in gGroupLocationSchedule.Columns.OfType <CheckBoxEditableField>()) { dataTable.Columns.Add(field.DataField, typeof(bool)); } foreach (var row in qryList) { DataRow dataRow = dataTable.NewRow(); dataRow["GroupLocationId"] = row.GroupLocationId; dataRow["GroupName"] = row.GroupName; dataRow["LocationName"] = row.LocationName; foreach (var field in gGroupLocationSchedule.Columns.OfType <CheckBoxEditableField>()) { int scheduleId = int.Parse(field.DataField.Replace("scheduleField_", string.Empty)); dataRow[field.DataField] = row.ScheduleIdList.Any(a => a == scheduleId); } dataTable.Rows.Add(dataRow); } gGroupLocationSchedule.DataSource = dataTable; gGroupLocationSchedule.DataBind(); }
/// <summary> /// Binds the grid. /// </summary> protected void BindGrid() { AddScheduleColumns(); var rockContext = new RockContext(); var groupLocationService = new GroupLocationService(rockContext); var groupLocationQry = groupLocationService.Queryable(); int groupTypeId; // if this page has a PageParam for groupTypeId use that to limit which groupTypeId to see. Otherwise, use the groupTypeId specified in the filter int?groupTypeIdPageParam = this.PageParameter("groupTypeId").AsInteger(false); if (groupTypeIdPageParam.HasValue) { groupTypeId = groupTypeIdPageParam ?? Rock.Constants.All.Id; } else { groupTypeId = ddlGroupType.SelectedValueAsInt() ?? Rock.Constants.All.Id; } if (groupTypeId != Rock.Constants.All.Id) { var descendantGroupTypeIds = new GroupTypeService(rockContext).GetAllAssociatedDescendents(groupTypeId).Select(a => a.Id); // filter to groups that either are of the GroupType or are of a GroupType that has the selected GroupType as a parent (ancestor) groupLocationQry = groupLocationQry.Where(a => a.Group.GroupType.Id == groupTypeId || descendantGroupTypeIds.Contains(a.Group.GroupTypeId)); } if (gGroupLocationSchedule.SortProperty != null) { groupLocationQry = groupLocationQry.Sort(gGroupLocationSchedule.SortProperty); } else { groupLocationQry = groupLocationQry.OrderBy(a => a.Group.Name).ThenBy(a => a.Location.Name); } var qryList = groupLocationQry.Select(a => new { GroupLocationId = a.Id, GroupName = a.Group.Name, LocationName = a.Location.Name, ScheduleIdList = a.Schedules.Select(s => s.Id), a.LocationId }).ToList(); int parentLocationId = pkrParentLocation.SelectedValueAsInt() ?? Rock.Constants.All.Id; if (parentLocationId != Rock.Constants.All.Id) { var descendantLocationIds = new LocationService(rockContext).GetAllDescendents(parentLocationId).Select(a => a.Id); qryList = qryList.Where(a => descendantLocationIds.Contains(a.LocationId)).ToList(); } // put stuff in a datatable so we can dynamically have columns for each Schedule DataTable dataTable = new DataTable(); dataTable.Columns.Add("GroupLocationId"); dataTable.Columns.Add("GroupName"); dataTable.Columns.Add("LocationName"); foreach (var field in gGroupLocationSchedule.Columns.OfType <CheckBoxEditableField>()) { dataTable.Columns.Add(field.DataField, typeof(bool)); } foreach (var row in qryList) { DataRow dataRow = dataTable.NewRow(); dataRow["GroupLocationId"] = row.GroupLocationId; dataRow["GroupName"] = row.GroupName; dataRow["LocationName"] = row.LocationName; foreach (var field in gGroupLocationSchedule.Columns.OfType <CheckBoxEditableField>()) { int scheduleId = int.Parse(field.DataField.Replace("scheduleField_", string.Empty)); dataRow[field.DataField] = row.ScheduleIdList.Any(a => a == scheduleId); } dataTable.Rows.Add(dataRow); } gGroupLocationSchedule.DataSource = dataTable; gGroupLocationSchedule.DataBind(); }
/// <summary> /// Gets the attendees. /// </summary> private IList <RosterAttendee> GetAttendees(RockContext rockContext) { var startDateTime = RockDateTime.Today; CampusCache campusCache = GetCampusFromContext(); DateTime currentDateTime; if (campusCache != null) { currentDateTime = campusCache.CurrentDateTime; } else { currentDateTime = RockDateTime.Now; } // Get all Attendance records for the current day and location var attendanceQuery = new AttendanceService(rockContext).Queryable().Where(a => a.StartDateTime >= startDateTime && a.DidAttend == true && a.StartDateTime <= currentDateTime && a.PersonAliasId.HasValue && a.Occurrence.GroupId.HasValue && a.Occurrence.ScheduleId.HasValue && a.Occurrence.LocationId.HasValue && a.Occurrence.ScheduleId.HasValue); if (campusCache != null) { // limit locations (rooms) to locations within the selected campus var campusLocationIds = new LocationService(rockContext).GetAllDescendentIds(campusCache.LocationId.Value).ToList(); attendanceQuery = attendanceQuery.Where(a => campusLocationIds.Contains(a.Occurrence.LocationId.Value)); } var selectedScheduleIds = lbSchedules.SelectedValues.AsIntegerList().Where(a => a > 0).ToList(); var selectedGroupIds = GetSelectedGroupIds(); if (selectedScheduleIds.Any()) { attendanceQuery = attendanceQuery.Where(a => selectedScheduleIds.Contains(a.Occurrence.ScheduleId.Value)); } if (selectedGroupIds.Any()) { if (cbIncludeChildGroups.Checked) { var groupService = new GroupService(rockContext); foreach (var groupId in selectedGroupIds.ToList()) { var childGroupIds = groupService.GetAllDescendentGroupIds(groupId, false); selectedGroupIds.AddRange(childGroupIds); } } attendanceQuery = attendanceQuery.Where(a => selectedGroupIds.Contains(a.Occurrence.GroupId.Value)); } else { var checkinAreaFilter = CheckinManagerHelper.GetCheckinAreaFilter(this); if (checkinAreaFilter != null) { // if there is a checkin area filter, limit to groups within the selected check-in area var checkinAreaGroupTypeIds = new GroupTypeService(rockContext).GetCheckinAreaDescendants(checkinAreaFilter.Id).Select(a => a.Id).ToList(); selectedGroupIds = new GroupService(rockContext).Queryable().Where(a => checkinAreaGroupTypeIds.Contains(a.GroupTypeId)).Select(a => a.Id).ToList(); attendanceQuery = attendanceQuery.Where(a => selectedGroupIds.Contains(a.Occurrence.GroupId.Value)); } } RosterStatusFilter rosterStatusFilter = this.GetAttributeValue(AttributeKey.FilterBy).ConvertToEnumOrNull <RosterStatusFilter>() ?? RosterStatusFilter.CheckedIn; attendanceQuery = CheckinManagerHelper.FilterByRosterStatusFilter(attendanceQuery, rosterStatusFilter); var attendanceList = RosterAttendeeAttendance.Select(attendanceQuery).ToList(); attendanceList = CheckinManagerHelper.FilterByActiveCheckins(currentDateTime, attendanceList); attendanceList = attendanceList.Where(a => a.Person != null).ToList(); if (tbSearch.Text.IsNotNullOrWhiteSpace()) { // search by name var searchValue = tbSearch.Text; // ignore the result of reversed (LastName, FirstName vs FirstName LastName bool reversed; var personIds = new PersonService(rockContext) .GetByFullName(searchValue, false, false, false, out reversed) .AsNoTracking() .Select(a => a.Id) .ToList(); attendanceList = attendanceList.Where(a => personIds.Contains(a.PersonId)).ToList(); } var attendees = RosterAttendee.GetFromAttendanceList(attendanceList); return(attendees); }
/// <summary> /// Binds the grid. /// </summary> protected void BindGrid() { AddScheduleColumns(); var rockContext = new RockContext(); var groupLocationService = new GroupLocationService(rockContext); var groupTypeService = new GroupTypeService(rockContext); IEnumerable <GroupTypePath> groupPaths = new List <GroupTypePath>(); var groupLocationQry = groupLocationService.Queryable(); int groupTypeId; // if this page has a PageParam for groupTypeId use that to limit which groupTypeId to see. Otherwise, use the groupTypeId specified in the filter int?groupTypeIdPageParam = this.PageParameter("groupTypeId").AsIntegerOrNull(); if (groupTypeIdPageParam.HasValue) { groupTypeId = groupTypeIdPageParam ?? Rock.Constants.All.Id; } else { groupTypeId = ddlGroupType.SelectedValueAsInt() ?? Rock.Constants.All.Id; } if (groupTypeId != Rock.Constants.All.Id) { var descendantGroupTypeIds = groupTypeService.GetAllAssociatedDescendents(groupTypeId).Select(a => a.Id); // filter to groups that either are of the GroupType or are of a GroupType that has the selected GroupType as a parent (ancestor) groupLocationQry = groupLocationQry.Where(a => a.Group.GroupType.Id == groupTypeId || descendantGroupTypeIds.Contains(a.Group.GroupTypeId)); groupPaths = groupTypeService.GetAllAssociatedDescendentsPath(groupTypeId); } else { // if no specific GroupType is specified, show all GroupTypes with GroupTypePurpose of Checkin Template and their descendents (since this blocktype is specifically for Checkin) int groupTypePurposeCheckInTemplateId = DefinedValueCache.Read(new Guid(Rock.SystemGuid.DefinedValue.GROUPTYPE_PURPOSE_CHECKIN_TEMPLATE)).Id; List <int> descendantGroupTypeIds = new List <int>(); foreach (var templateGroupType in groupTypeService.Queryable().Where(a => a.GroupTypePurposeValueId == groupTypePurposeCheckInTemplateId)) { foreach (var childGroupType in groupTypeService.GetChildGroupTypes(templateGroupType.Id)) { descendantGroupTypeIds.Add(childGroupType.Id); descendantGroupTypeIds.AddRange(groupTypeService.GetAllAssociatedDescendents(childGroupType.Id).Select(a => a.Id).ToList()); } } groupLocationQry = groupLocationQry.Where(a => descendantGroupTypeIds.Contains(a.Group.GroupTypeId)); } if (gGroupLocationSchedule.SortProperty != null) { groupLocationQry = groupLocationQry.Sort(gGroupLocationSchedule.SortProperty); } else { groupLocationQry = groupLocationQry.OrderBy(a => a.Group.Name).ThenBy(a => a.Location.Name); } var qryList = groupLocationQry.Select(a => new { GroupLocationId = a.Id, GroupName = a.Group.Name, LocationName = a.Location.Name, ScheduleIdList = a.Schedules.Select(s => s.Id), a.LocationId, GroupTypeId = a.Group.GroupTypeId }).ToList(); int parentLocationId = pkrParentLocation.SelectedValueAsInt() ?? Rock.Constants.All.Id; if (parentLocationId != Rock.Constants.All.Id) { var descendantLocationIds = new LocationService(rockContext).GetAllDescendents(parentLocationId).Select(a => a.Id); qryList = qryList.Where(a => descendantLocationIds.Contains(a.LocationId)).ToList(); } // put stuff in a datatable so we can dynamically have columns for each Schedule DataTable dataTable = new DataTable(); dataTable.Columns.Add("GroupLocationId"); dataTable.Columns.Add("GroupName"); dataTable.Columns.Add("LocationName"); dataTable.Columns.Add("Path"); foreach (var field in gGroupLocationSchedule.Columns.OfType <CheckBoxEditableField>()) { dataTable.Columns.Add(field.DataField, typeof(bool)); } foreach (var row in qryList) { DataRow dataRow = dataTable.NewRow(); dataRow["GroupLocationId"] = row.GroupLocationId; dataRow["GroupName"] = row.GroupName; dataRow["LocationName"] = row.LocationName; dataRow["Path"] = groupPaths.Where(gt => gt.GroupTypeId == row.GroupTypeId).Select(gt => gt.Path).FirstOrDefault(); foreach (var field in gGroupLocationSchedule.Columns.OfType <CheckBoxEditableField>()) { int scheduleId = int.Parse(field.DataField.Replace("scheduleField_", string.Empty)); dataRow[field.DataField] = row.ScheduleIdList.Any(a => a == scheduleId); } dataTable.Rows.Add(dataRow); } gGroupLocationSchedule.DataSource = dataTable; gGroupLocationSchedule.DataBind(); }