protected void btnImport_Click(object sender, EventArgs e) { btnImport.Enabled = false; var rockContext = new RockContext(); var volunteerTrackingContext = new VolunteerTrackingContext(); var volunteerMembershipService = new VolunteerMembershipService(volunteerTrackingContext); var groupService = new GroupService(rockContext); var groupTypeGuids = GetAttributeValue("GroupTypes").SplitDelimitedValues().AsGuidList(); var groupTypeIds = new GroupTypeService(rockContext).GetByGuids(groupTypeGuids).Select(gt => gt.Id); var groups = groupService.Queryable().Where(g => groupTypeIds.Contains(g.GroupTypeId)).ToList(); foreach (var group in groups) { foreach (var groupMember in group.Members) { var volunteerMember = volunteerMembershipService.Queryable().FirstOrDefault(v => v.GroupId == groupMember.GroupId && v.PersonId == groupMember.PersonId && v.LeftGroupDateTime == null); if (volunteerMember == null) { volunteerMember = new VolunteerMembership { GroupId = groupMember.GroupId, PersonId = groupMember.PersonId, GroupRoleId = groupMember.GroupRoleId, JoinedGroupDateTime = DateTime.Now }; volunteerMembershipService.Add(volunteerMember); } } } volunteerTrackingContext.SaveChanges(); btnImport.Enabled = true; }
/// <summary> /// Show the block content. /// </summary> protected void ShowDetails() { var group = ContextEntity <Group>(); var groupMember = ContextEntity <GroupMember>(); if (groupMember != null) { group = groupMember.Group; } pnlDetails.Visible = false; // // Only show the panel and content if the group type is a fundraising opportunity. // var rockContext = new RockContext(); var groupService = new GroupService(rockContext); var groupTypeIdFundraising = GroupTypeCache.Get(Rock.SystemGuid.GroupType.GROUPTYPE_FUNDRAISINGOPPORTUNITY.AsGuid()).Id; var fundraisingGroupTypeIdList = new GroupTypeService(rockContext).Queryable().Where(a => a.Id == groupTypeIdFundraising || a.InheritedGroupTypeId == groupTypeIdFundraising).Select(a => a.Id).ToList(); if (group != null && fundraisingGroupTypeIdList.Contains(group.GroupTypeId)) { pnlDetails.Visible = true; BindGrid(); } }
/// <summary> /// Binds the grid. /// </summary> private void ShowView() { RockContext rockContext = new RockContext(); GroupService groupService = new GroupService(rockContext); var groupTypeIdFundraising = GroupTypeCache.Get(Rock.SystemGuid.GroupType.GROUPTYPE_FUNDRAISINGOPPORTUNITY.AsGuid()).Id; var fundraisingGroupTypeIdList = new GroupTypeService(rockContext).Queryable().Where(a => a.Id == groupTypeIdFundraising || a.InheritedGroupTypeId == groupTypeIdFundraising).Select(a => a.Id).ToList(); var fundraisingGroupList = groupService.Queryable() .Where(a => a.IsActive && fundraisingGroupTypeIdList.Contains(a.GroupTypeId)) .WhereAttributeValue(rockContext, "ShowPublic", true.ToString()).ToList(); foreach (var group in fundraisingGroupList) { group.LoadAttributes(rockContext); } var fundraisingOpportunityTypes = this.GetAttributeValue("FundraisingOpportunityTypes").SplitDelimitedValues().AsGuidList(); if (fundraisingOpportunityTypes.Any()) { fundraisingGroupList = fundraisingGroupList.Where(a => fundraisingOpportunityTypes.Contains(a.GetAttributeValue("OpportunityType").AsGuid())).ToList(); } fundraisingGroupList = fundraisingGroupList.OrderBy(g => DateRange.FromDelimitedValues(g.GetAttributeValue("OpportunityDateRange")).Start).ThenBy(g => g.GetAttributeValue("Opportunity Title")).ToList(); var mergeFields = Rock.Lava.LavaHelper.GetCommonMergeFields(this.RockPage, null, new Rock.Lava.CommonMergeFieldsOptions { GetLegacyGlobalMergeFields = false }); mergeFields.Add("GroupList", fundraisingGroupList); mergeFields.Add("DetailsPage", LinkedPageRoute("DetailsPage")); string lavaTemplate = this.GetAttributeValue("LavaTemplate"); lViewHtml.Text = lavaTemplate.ResolveMergeFields(mergeFields); }
/// <summary> /// Shows the readonly details. /// </summary> /// <param name="groupType">The groupType.</param> private void ShowReadonlyDetails(GroupType groupType) { SetEditMode(false); if (groupType != null) { hfGroupTypeId.SetValue(groupType.Id); lReadOnlyTitle.Text = groupType.ToString().FormatAsHtmlTitle(); lDescription.Text = groupType.Description; groupType.LoadAttributes(); hlType.Text = groupType.GetAttributeValue("CheckInType"); hlType.Visible = true; DescriptionList mainDetailsDescList = new DescriptionList(); DescriptionList leftDetailsDescList = new DescriptionList(); DescriptionList rightDetailsDescList = new DescriptionList(); string scheduleList = string.Empty; using (var rockContext = new RockContext()) { var descendantGroupTypeIds = new GroupTypeService(rockContext).GetCheckinAreaDescendants(groupType.Id).Select(a => a.Id); scheduleList = new GroupLocationService(rockContext) .Queryable().AsNoTracking() .Where(a => a.Group.GroupType.Id == groupType.Id || descendantGroupTypeIds.Contains(a.Group.GroupTypeId)) .SelectMany(a => a.Schedules) .Select(s => s.Name) .Distinct() .OrderBy(s => s) .ToList() .AsDelimited(", "); } if (!string.IsNullOrWhiteSpace(scheduleList)) { mainDetailsDescList.Add("Scheduled Times", scheduleList); } groupType.LoadAttributes(); if (groupType.AttributeValues.ContainsKey("core_checkin_CheckInType")) { leftDetailsDescList.Add("Check-in Type", groupType.AttributeValues["core_checkin_CheckInType"].ValueFormatted); } if (groupType.AttributeValues.ContainsKey("core_checkin_SearchType")) { var searchType = groupType.AttributeValues["core_checkin_SearchType"]; rightDetailsDescList.Add("Search Type", searchType.ValueFormatted); var searchTypeGuid = searchType.Value.AsGuid(); if (searchTypeGuid.Equals(Rock.SystemGuid.DefinedValue.CHECKIN_SEARCH_TYPE_NAME_AND_PHONE.AsGuid()) || searchTypeGuid.Equals(Rock.SystemGuid.DefinedValue.CHECKIN_SEARCH_TYPE_PHONE_NUMBER.AsGuid())) { rightDetailsDescList.Add("Phone Number Compare", groupType.AttributeValues["core_checkin_PhoneSearchType"].ValueFormatted); } } lblMainDetails.Text = mainDetailsDescList.Html; lblLeftDetails.Text = leftDetailsDescList.Html; lblRightDetails.Text = rightDetailsDescList.Html; } }
/// <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 metric values. /// </summary> /// <param name="isPrimary">if set to <c>true</c> [is primary].</param> /// <returns></returns> protected List <MetricValue> GetMetricValues(bool isPrimary) { var rockContext = new RockContext(); var metricService = new MetricService(rockContext); List <Guid> sourceGuids = null; var preKey = isPrimary ? string.Empty : "Comparison"; IQueryable <MetricValue> metricValues = null; var attributeValue = GetAttributeValue(preKey + "MetricSource"); if (string.IsNullOrWhiteSpace(attributeValue)) { attributeValue = string.Empty; } var pairs = MetricCategoriesFieldAttribute.GetValueAsGuidPairs(attributeValue); sourceGuids = pairs.Select(p => p.MetricGuid).ToList(); if (sourceGuids.Any()) { metricValues = metricService.GetByGuids(sourceGuids).SelectMany(m => m.MetricValues); } else { nbMetricWarning.Visible = true; pnlMetricDisplay.Visible = false; return(null); } if (GetAttributeValue(preKey + "RespectCampusContext").AsBoolean()) { var campusContext = RockPage.GetCurrentContext(EntityTypeCache.Get(typeof(Campus))); if (campusContext != null) { metricValues = FilterMetricValuesByPartition(metricValues, "Campus", campusContext.Id); } } if (GetAttributeValue(preKey + "RespectGroupContext").AsBoolean()) { var groupTypeContext = RockPage.GetCurrentContext(EntityTypeCache.Get(typeof(GroupType))); var groupContext = RockPage.GetCurrentContext(EntityTypeCache.Get(typeof(Group))); if (groupContext != null) { metricValues = FilterMetricValuesByPartition(metricValues, "Group", groupContext.Id); } else if (groupTypeContext != null) { var groupTypeIds = new GroupTypeService(rockContext).GetAllAssociatedDescendents(groupTypeContext.Id).Select(gt => gt.Id); var groupIds = new GroupService(rockContext).Queryable().Where(g => groupTypeIds.Contains(g.GroupTypeId)).Select(g => g.Id); metricValues = metricValues.Where(a => a.MetricValuePartitions.Any(mvp => mvp.MetricPartition.Label == "Group" && groupIds.Any(i => i == mvp.EntityId))); } } if (GetAttributeValue(preKey + "RespectDateContext").AsBoolean()) { var dateRangeString = RockPage.GetUserPreference(ContextPreferenceName); if (!string.IsNullOrWhiteSpace(dateRangeString)) { var dateRange = SlidingDateRangePicker.CalculateDateRangeFromDelimitedValues(dateRangeString); metricValues = metricValues.Where(v => v.MetricValueDateTime >= dateRange.Start && v.MetricValueDateTime <= dateRange.End); } } if (GetAttributeValue(preKey + "RespectScheduleContext").AsBoolean()) { var scheduleContext = RockPage.GetCurrentContext(EntityTypeCache.Get(typeof(Schedule))); if (scheduleContext != null) { metricValues = FilterMetricValuesByPartition(metricValues, "Schedule", scheduleContext.Id); } } return(metricValues.ToList()); }
/// <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> /// Executes the specified workflow. /// </summary> /// <param name="rockContext">The rock context.</param> /// <param name="action">The action.</param> /// <param name="entity">The entity.</param> /// <param name="errorMessages">The error messages.</param> /// <returns></returns> public override bool Execute(RockContext rockContext, WorkflowAction action, object entity, out List <string> errorMessages) { errorMessages = new List <string>(); // Determine which group to add the person to Group group = null; int? groupRoleId = null; var guidGroupAttribute = GetAttributeValue(action, AttributeKey.GroupKey).AsGuidOrNull(); if (guidGroupAttribute.HasValue) { var attributeGroup = AttributeCache.Get(guidGroupAttribute.Value, rockContext); if (attributeGroup != null) { var groupGuid = action.GetWorkflowAttributeValue(guidGroupAttribute.Value).AsGuidOrNull(); if (groupGuid.HasValue) { group = new GroupService(rockContext).Get(groupGuid.Value); if (group != null) { // use the group's grouptype's default group role if a group role wasn't specified groupRoleId = GroupTypeCache.Get(group.GroupTypeId).DefaultGroupRoleId; } } } } if (group == null) { errorMessages.Add("No group was provided"); } else { // Check if this is a security group and show an error if that functionality has been disabled. var disableSecurityGroups = GetAttributeValue(action, AttributeKey.DisableSecurityGroups).AsBooleanOrNull() ?? false; if (group.IsSecurityRoleOrSecurityGroupType() && disableSecurityGroups) { errorMessages.Add($"\"{group.Name}\" is a Security group. The settings for this workflow action do not allow it to add a person to a security group."); } // If LimitToGroupsOfType has any values check if this Group's GroupType is in that list var limitToGroupsOfTypeGuid = GetAttributeValue(action, AttributeKey.LimitToGroupsOfType).AsGuidOrNull(); if (limitToGroupsOfTypeGuid.HasValue) { var limitToGroupType = GroupTypeCache.Get(limitToGroupsOfTypeGuid.Value); var limitToGroupTypeIds = new GroupTypeService(rockContext).GetChildGroupTypes(limitToGroupType.Id).Select(a => a.Id).ToList(); limitToGroupTypeIds.Add(limitToGroupType.Id); if (!limitToGroupTypeIds.Contains(group.GroupTypeId)) { errorMessages.Add($"The group type for group \"{group.Name} is \"{group.GroupType.Name}\". This action is configured to only add persons to groups of type \"{limitToGroupType.Name}\" and its child types."); } } // If LimitToGroupsUnderSpecificParentGroup has any values check if this Group is a child of that group var limitToChildGroupsOfGroupGuid = GetAttributeValue(action, AttributeKey.LimitToGroupsUnderSpecificParentGroup).AsGuidOrNull(); if (limitToChildGroupsOfGroupGuid.HasValue) { var groupService = new GroupService(rockContext); var limitToChildGroupsOfGroup = groupService.Get(limitToChildGroupsOfGroupGuid.Value); var limitToGroupIds = groupService.GetAllDescendentGroupIds(limitToChildGroupsOfGroup.Id, true); limitToGroupIds.Add(limitToChildGroupsOfGroup.Id); if (!limitToGroupIds.Contains(group.Id)) { errorMessages.Add($"Cannot add the person to group \"{group.Name}\". This workflow action is configured to only add persons to groups that are a descendant of Group {limitToChildGroupsOfGroup.Name}."); } } } if (!groupRoleId.HasValue) { errorMessages.Add("Provided group doesn't have a default group role"); } // determine the person that will be added to the group Person person = null; // get the Attribute.Guid for this workflow's Person Attribute so that we can lookup the value var guidPersonAttribute = GetAttributeValue(action, AttributeKey.PersonKey).AsGuidOrNull(); if (guidPersonAttribute.HasValue) { var attributePerson = AttributeCache.Get(guidPersonAttribute.Value, rockContext); if (attributePerson != null) { string attributePersonValue = action.GetWorkflowAttributeValue(guidPersonAttribute.Value); if (!string.IsNullOrWhiteSpace(attributePersonValue)) { if (attributePerson.FieldType.Class == typeof(Rock.Field.Types.PersonFieldType).FullName) { Guid personAliasGuid = attributePersonValue.AsGuid(); if (!personAliasGuid.IsEmpty()) { person = new PersonAliasService(rockContext).Queryable() .Where(a => a.Guid.Equals(personAliasGuid)) .Select(a => a.Person) .FirstOrDefault(); } } else { errorMessages.Add("The attribute used to provide the person was not of type 'Person'."); } } } } if (person == null) { errorMessages.Add(string.Format("Person could not be found for selected value ('{0}')!", guidPersonAttribute.ToString())); } // Add Person to Group if (!errorMessages.Any()) { var groupMemberService = new GroupMemberService(rockContext); var groupMember = groupMemberService.GetByGroupIdAndPersonIdAndPreferredGroupRoleId(group.Id, person.Id, groupRoleId.Value); bool isNew = false; if (groupMember == null) { groupMember = new GroupMember(); groupMember.PersonId = person.Id; groupMember.GroupId = group.Id; isNew = true; } else { action.AddLogEntry($"{person.FullName} was already a member of the selected group.", true); } groupMember.GroupRoleId = groupRoleId.Value; groupMember.GroupMemberStatus = GroupMemberStatus.Active; if (groupMember.IsValidGroupMember(rockContext)) { if (isNew) { groupMemberService.Add(groupMember); } rockContext.SaveChanges(); } else { // if the group member couldn't be added (for example, one of the group membership rules didn't pass), add the validation messages to the errormessages errorMessages.AddRange(groupMember.ValidationResults.Select(a => a.ErrorMessage)); } } errorMessages.ForEach(m => action.AddLogEntry(m, true)); return(true); }
/// <summary> /// Loads the check in groups check boxes. /// </summary> private Dictionary <int, string> LoadCheckInGroupsCheckBoxes(int checkinAreaTypeId) { var items = new Dictionary <int, string>(); var occurrenceIds = GetOccurrencesQuery() .Select(o => o.Id) .ToList(); var occurrencesAndGroups = GetOccurrencesQuery() .ToDictionary(k => k.Id, v => v.GroupId.Value); // if we have occurrences for the day, keep going if (occurrenceIds.Count > 0) { // get the attendance from the occurences var attendanceQuery = new AttendanceService(_rockContext) .Queryable() .AsNoTracking() .Where(a => occurrenceIds.Contains(a.OccurrenceId)); if (SelectedCampus.IsNotNullOrWhiteSpace()) { var campusId = SelectedCampus.AsInteger(); attendanceQuery = attendanceQuery.Where(a => a.CampusId.HasValue && a.CampusId.Value.Equals(campusId)); } var attendanceDictionary = attendanceQuery .ToDictionary(k => k.Id, v => v.OccurrenceId); // if we have attendance, keep going if (attendanceDictionary.Count > 0) { // get groups with attendance var attendanceGroups = occurrencesAndGroups .Where(o => attendanceDictionary.ContainsValue(o.Key)) .Select(o => o.Value) .Distinct() .ToList(); // get the group types var checkinFilterId = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.GROUPTYPE_PURPOSE_CHECKIN_FILTER).Id; var groupTypeIds = new GroupTypeService(_rockContext) .GetAllAssociatedDescendentsOrdered(checkinAreaTypeId) .Where(t => !t.GroupTypePurposeValueId.HasValue || (t.GroupTypePurposeValueId.HasValue && t.GroupTypePurposeValueId != checkinFilterId)) .Distinct() .Select(t => t.Id) .ToList(); if (!groupTypeIds.Contains(checkinAreaTypeId)) { groupTypeIds.Add(checkinAreaTypeId); } // get the groups with attendance items = new GroupService(_rockContext) .Queryable() .AsNoTracking() .Where(g => g.IsActive && groupTypeIds.Contains(g.GroupTypeId) && attendanceGroups.Contains(g.Id)) .Distinct() .OrderBy(g => g.Order) .ThenBy(g => g.Name) .ToDictionary(k => k.Id, v => v.Name); } } return(items); }
/// <summary> /// Checks the settings. If false is returned, it's expected that the caller will make /// the nbNotice visible to inform the user of the "settings" error. /// </summary> /// <returns>true if settings are valid; false otherwise</returns> private bool CheckSettings() { _rockContext = _rockContext ?? new RockContext(); _mode = GetAttributeValue("Mode"); _autoFill = GetAttributeValue("AutoFillForm").AsBoolean(); var groupService = new GroupService(_rockContext); bool groupIsFromQryString = true; Guid?groupGuid = GetAttributeValue("Group").AsGuidOrNull(); if (groupGuid.HasValue) { _group = groupService.Get(groupGuid.Value); groupIsFromQryString = false; } if (_group == null) { groupGuid = PageParameter("GroupGuid").AsGuidOrNull(); if (groupGuid.HasValue) { _group = groupService.Get(groupGuid.Value); } } if (_group == null && GetAttributeValue("EnablePassingGroupId").AsBoolean(false)) { int?groupId = PageParameter("GroupId").AsIntegerOrNull(); if (groupId.HasValue) { _group = groupService.Get(groupId.Value); } } if (_group == null) { nbNotice.Heading = "Unknown Group"; nbNotice.Text = "<p>This page requires a valid group identifying parameter and there was not one provided.</p>"; return(false); } else { Guid RsvpGroupTypeGuid = "1A082EFF-30DA-44B2-8E48-02385C20828E".AsGuid(); var groupTypeGuids = new GroupTypeService(_rockContext).Queryable() .AsNoTracking() .Where(g => g.Guid == RsvpGroupTypeGuid || g.InheritedGroupType.Guid == RsvpGroupTypeGuid) .Select(g => g.Guid) .ToList(); if (groupIsFromQryString && groupTypeGuids.Any() && !groupTypeGuids.Contains(_group.GroupType.Guid)) { _group = null; nbNotice.Heading = "Invalid Group"; nbNotice.Text = "<p>The selected group is a restricted group type therefore this block cannot be used to add people to these groups (unless configured to allow).</p>"; return(false); } else { _defaultGroupRole = _group.GroupType.DefaultGroupRole; } } _dvcConnectionStatus = DefinedValueCache.Get(GetAttributeValue("ConnectionStatus").AsGuid()); if (_dvcConnectionStatus == null) { nbNotice.Heading = "Invalid Connection Status"; nbNotice.Text = "<p>The selected Connection Status setting does not exist.</p>"; return(false); } _dvcRecordStatus = DefinedValueCache.Get(GetAttributeValue("RecordStatus").AsGuid()); if (_dvcRecordStatus == null) { nbNotice.Heading = "Invalid Record Status"; nbNotice.Text = "<p>The selected Record Status setting does not exist.</p>"; return(false); } _married = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.PERSON_MARITAL_STATUS_MARRIED.AsGuid()); _homeAddressType = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.GROUP_LOCATION_TYPE_HOME.AsGuid()); _familyType = GroupTypeCache.Get(Rock.SystemGuid.GroupType.GROUPTYPE_FAMILY.AsGuid()); _adultRole = _familyType.Roles.FirstOrDefault(r => r.Guid.Equals(Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_ADULT.AsGuid())); if (_married == null || _homeAddressType == null || _familyType == null || _adultRole == null) { nbNotice.Heading = "Missing System Value"; nbNotice.Text = "<p>There is a missing or invalid system value. Check the settings for Marital Status of 'Married', Location Type of 'Home', Group Type of 'Family', and Family Group Role of 'Adult'.</p>"; return(false); } return(true); }