/// <summary> /// Shows the connectionOpportunity requirements statuses. /// </summary> private void ShowConnectionOpportunityRequirementsStatuses() { using ( var rockContext = new RockContext() ) { int connectionRequestId = hfConnectionRequestId.Value.AsInteger(); var connectionOpportunityId = hfConnectionOpportunityId.Value.AsInteger(); ConnectionRequest connectionRequest = null; bool passedAllRequirements = true; connectionRequest = new ConnectionRequestService( rockContext ).Get( connectionRequestId ); var groupMember = new GroupMember { Id = 0 }; groupMember.GroupId = connectionRequest.AssignedGroupId.Value; groupMember.Group = new GroupService( rockContext ).Get( groupMember.GroupId ); groupMember.GroupRoleId = groupMember.Group.GroupType.DefaultGroupRoleId ?? 0; groupMember.GroupMemberStatus = GroupMemberStatus.Active; cblManualRequirements.Items.Clear(); lRequirementsLabels.Text = string.Empty; IEnumerable<GroupRequirementStatus> requirementsResults; if ( groupMember.IsNewOrChangedGroupMember( rockContext ) ) { requirementsResults = groupMember.Group.PersonMeetsGroupRequirements( connectionRequest.PersonAlias.PersonId, connectionRequest.ConnectionOpportunity.GroupMemberRoleId ); } else { requirementsResults = groupMember.GetGroupRequirementsStatuses().ToList(); } // hide requirements section if there are none if ( !requirementsResults.Where( a => a.MeetsGroupRequirement != MeetsGroupRequirement.NotApplicable ).Any() ) { rcwRequirements.Visible = false; } // only show the requirements that apply to the GroupRole (or all Roles) foreach ( var requirementResult in requirementsResults.Where( a => a.MeetsGroupRequirement != MeetsGroupRequirement.NotApplicable ) ) { if ( requirementResult.GroupRequirement.GroupRequirementType.RequirementCheckType == RequirementCheckType.Manual ) { var checkboxItem = new ListItem( requirementResult.GroupRequirement.GroupRequirementType.CheckboxLabel, requirementResult.GroupRequirement.Id.ToString() ); if ( string.IsNullOrEmpty( checkboxItem.Text ) ) { checkboxItem.Text = requirementResult.GroupRequirement.GroupRequirementType.Name; } checkboxItem.Selected = requirementResult.MeetsGroupRequirement == MeetsGroupRequirement.Meets; cblManualRequirements.Items.Add( checkboxItem ); } else { string labelText; string labelType; string labelTooltip; if ( requirementResult.MeetsGroupRequirement == MeetsGroupRequirement.Meets ) { labelText = requirementResult.GroupRequirement.GroupRequirementType.PositiveLabel; labelType = "success"; } else if ( requirementResult.MeetsGroupRequirement == MeetsGroupRequirement.MeetsWithWarning ) { labelText = requirementResult.GroupRequirement.GroupRequirementType.WarningLabel; labelType = "warning"; } else { passedAllRequirements = false; labelText = requirementResult.GroupRequirement.GroupRequirementType.NegativeLabel; labelType = "danger"; } if ( string.IsNullOrEmpty( labelText ) ) { labelText = requirementResult.GroupRequirement.GroupRequirementType.Name; } if ( requirementResult.MeetsGroupRequirement == MeetsGroupRequirement.MeetsWithWarning ) { labelTooltip = requirementResult.RequirementWarningDateTime.HasValue ? "Last Checked: " + requirementResult.RequirementWarningDateTime.Value.ToString( "g" ) : "Not calculated yet"; } else { labelTooltip = requirementResult.LastRequirementCheckDateTime.HasValue ? "Last Checked: " + requirementResult.LastRequirementCheckDateTime.Value.ToString( "g" ) : "Not calculated yet"; } lRequirementsLabels.Text += string.Format( @"<span class='label label-{1}' title='{2}'>{0}</span> ", labelText, labelType, labelTooltip ); } } var requirementsWithErrors = requirementsResults.Where( a => a.MeetsGroupRequirement == MeetsGroupRequirement.Error ).ToList(); if ( requirementsWithErrors.Any() ) { nbRequirementsErrors.Visible = true; nbRequirementsErrors.Text = string.Format( "An error occurred in one or more of the requirement calculations: <br /> {0}", requirementsWithErrors.AsDelimited( "<br />" ) ); } else { nbRequirementsErrors.Visible = false; } if ( passedAllRequirements || ( groupMember.Group.MustMeetRequirementsToAddMember.HasValue && !groupMember.Group.MustMeetRequirementsToAddMember.Value ) ) { if ( passedAllRequirements ) { lbConnect.RemoveCssClass( "js-confirm-connect" ); } else { lbConnect.AddCssClass( "js-confirm-connect" ); } lbConnect.Enabled = true; } else { lbConnect.Enabled = false; } } }