private void AddFamilyMember() { var rows = nfmMembers.FamilyMemberRows; var familyMemberGuid = Guid.NewGuid(); string familyMemberGuidString = familyMemberGuid.ToString().Replace( "-", "_" ); var familyMemberRow = new NewFamilyMembersRow(); nfmMembers.Controls.Add( familyMemberRow ); familyMemberRow.ID = string.Format( "row_{0}", familyMemberGuidString ); familyMemberRow.RoleUpdated += familyMemberRow_RoleUpdated; familyMemberRow.DeleteClick += familyMemberRow_DeleteClick; familyMemberRow.PersonGuid = familyMemberGuid; familyMemberRow.Gender = Gender.Unknown; familyMemberRow.RequireGender = nfmMembers.RequireGender; familyMemberRow.RequireGrade = nfmMembers.RequireGrade; familyMemberRow.ValidationGroup = BlockValidationGroup; var familyGroupType = GroupTypeCache.GetFamilyGroupType(); if ( familyGroupType != null && familyGroupType.DefaultGroupRoleId.HasValue ) { familyMemberRow.RoleId = familyGroupType.DefaultGroupRoleId; familyMemberRow.ShowGrade = familyGroupType.DefaultGroupRoleId == _childRoleId; } else { familyMemberRow.ShowGrade = false; } var ConnectionStatusValue = DefinedValueCache.Read( GetAttributeValue( "DefaultConnectionStatus" ).AsGuid() ); if ( ConnectionStatusValue != null ) { familyMemberRow.ConnectionStatusValueId = ConnectionStatusValue.Id; } if ( rows.Count > 0 ) { familyMemberRow.LastName = rows[0].LastName; } var contactInfoRow = new NewFamilyContactInfoRow(); nfciContactInfo.Controls.Add( contactInfoRow ); contactInfoRow.ID = string.Format( "ci_row_{0}", familyMemberGuidString ); contactInfoRow.PersonGuid = familyMemberGuid; foreach ( var attributeControl in attributeControls ) { var attributeRow = new NewFamilyAttributesRow(); attributeControl.Controls.Add( attributeRow ); attributeRow.ID = string.Format( "{0}_{1}", attributeControl.ID, familyMemberGuidString ); attributeRow.AttributeList = attributeControl.AttributeList; attributeRow.PersonGuid = familyMemberGuid; } }
private void CreateControls( List<GroupMember> familyMembers, bool setSelection ) { // Load all the attribute controls attributeControls.Clear(); pnlAttributes.Controls.Clear(); foreach ( string categoryGuid in GetAttributeValue( "AttributeCategories" ).SplitDelimitedValues( false ) ) { Guid guid = Guid.Empty; if ( Guid.TryParse( categoryGuid, out guid ) ) { var category = CategoryCache.Read( guid ); if ( category != null ) { var attributeControl = new NewFamilyAttributes(); attributeControl.ClearRows(); pnlAttributes.Controls.Add( attributeControl ); attributeControls.Add( attributeControl ); attributeControl.ID = "familyAttributes_" + category.Id.ToString(); attributeControl.CategoryId = category.Id; foreach ( var attribute in new AttributeService( new RockContext() ).GetByCategoryId( category.Id ) ) { if ( attribute.IsAuthorized( Authorization.EDIT, CurrentPerson ) ) { attributeControl.AttributeList.Add( AttributeCache.Read( attribute ) ); } } } } } nfmMembers.ClearRows(); nfciContactInfo.ClearRows(); foreach ( var familyMember in familyMembers ) { string familyMemberGuidString = familyMember.Person.Guid.ToString().Replace( "-", "_" ); var familyMemberRow = new NewFamilyMembersRow(); nfmMembers.Controls.Add( familyMemberRow ); familyMemberRow.ID = string.Format( "row_{0}", familyMemberGuidString ); familyMemberRow.RoleUpdated += familyMemberRow_RoleUpdated; familyMemberRow.DeleteClick += familyMemberRow_DeleteClick; familyMemberRow.PersonGuid = familyMember.Person.Guid; familyMemberRow.RequireGender = nfmMembers.RequireGender; familyMemberRow.RequireGrade = nfmMembers.RequireGrade; familyMemberRow.RoleId = familyMember.GroupRoleId; familyMemberRow.ShowGrade = familyMember.GroupRoleId == _childRoleId; var contactInfoRow = new NewFamilyContactInfoRow(); nfciContactInfo.Controls.Add( contactInfoRow ); contactInfoRow.ID = string.Format( "ci_row_{0}", familyMemberGuidString ); contactInfoRow.PersonGuid = familyMember.Person.Guid; if ( _homePhone != null ) { var homePhoneNumber = familyMember.Person.PhoneNumbers.Where( p => p.NumberTypeValueId == _homePhone.Id ).FirstOrDefault(); if ( homePhoneNumber != null ) { contactInfoRow.HomePhoneNumber = homePhoneNumber.NumberFormatted; contactInfoRow.HomePhoneCountryCode = homePhoneNumber.CountryCode; } } if ( _cellPhone != null ) { var cellPhoneNumber = familyMember.Person.PhoneNumbers.Where( p => p.NumberTypeValueId == _cellPhone.Id ).FirstOrDefault(); if ( cellPhoneNumber != null ) { contactInfoRow.CellPhoneNumber = cellPhoneNumber.NumberFormatted; contactInfoRow.CellPhoneCountryCode = cellPhoneNumber.CountryCode; } } contactInfoRow.Email = familyMember.Person.Email; if ( setSelection ) { if ( familyMember.Person != null ) { familyMemberRow.TitleValueId = familyMember.Person.TitleValueId; familyMemberRow.FirstName = familyMember.Person.FirstName; familyMemberRow.LastName = familyMember.Person.LastName; familyMemberRow.SuffixValueId = familyMember.Person.SuffixValueId; familyMemberRow.Gender = familyMember.Person.Gender; familyMemberRow.BirthDate = familyMember.Person.BirthDate; familyMemberRow.ConnectionStatusValueId = familyMember.Person.ConnectionStatusValueId; familyMemberRow.GradeOffset = familyMember.Person.GradeOffset; } } foreach ( var attributeControl in attributeControls ) { var attributeRow = new NewFamilyAttributesRow(); attributeControl.Controls.Add( attributeRow ); attributeRow.ID = string.Format( "{0}_{1}", attributeControl.ID, familyMemberGuidString ); attributeRow.AttributeList = attributeControl.AttributeList; attributeRow.PersonGuid = familyMember.Person.Guid; if ( setSelection ) { attributeRow.SetEditValues( familyMember.Person ); } } } ShowPage( CurrentPageIndex ); }
private void CreateControls( bool setSelection ) { // Load all the attribute controls attributeControls.Clear(); pnlAttributes.Controls.Clear(); phDuplicates.Controls.Clear(); var rockContext = new RockContext(); var attributeService = new AttributeService( rockContext ); var locationService = new LocationService( rockContext ); foreach ( string categoryGuid in GetAttributeValue( "AttributeCategories" ).SplitDelimitedValues( false ) ) { Guid guid = Guid.Empty; if ( Guid.TryParse( categoryGuid, out guid ) ) { var category = CategoryCache.Read( guid ); if ( category != null ) { var attributeControl = new NewFamilyAttributes(); attributeControl.ClearRows(); pnlAttributes.Controls.Add( attributeControl ); attributeControls.Add( attributeControl ); attributeControl.ID = "familyAttributes_" + category.Id.ToString(); attributeControl.CategoryId = category.Id; foreach ( var attribute in attributeService.GetByCategoryId( category.Id ) ) { if ( attribute.IsAuthorized( Authorization.EDIT, CurrentPerson ) ) { attributeControl.AttributeList.Add( AttributeCache.Read( attribute ) ); } } } } } nfmMembers.ClearRows(); nfciContactInfo.ClearRows(); var groupMemberService = new GroupMemberService( rockContext ); var familyGroupType = GroupTypeCache.GetFamilyGroupType(); int adultRoleId = familyGroupType.Roles.First( a => a.Guid == Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_ADULT.AsGuid() ).Id; var homeLocationGuid = Rock.SystemGuid.DefinedValue.GROUP_LOCATION_TYPE_HOME.AsGuid(); var location = new Location(); acAddress.GetValues( location ); foreach ( var familyMember in FamilyMembers ) { string familyMemberGuidString = familyMember.Person.Guid.ToString().Replace( "-", "_" ); var familyMemberRow = new NewFamilyMembersRow(); nfmMembers.Controls.Add( familyMemberRow ); familyMemberRow.ID = string.Format( "row_{0}", familyMemberGuidString ); familyMemberRow.RoleUpdated += familyMemberRow_RoleUpdated; familyMemberRow.DeleteClick += familyMemberRow_DeleteClick; familyMemberRow.PersonGuid = familyMember.Person.Guid; familyMemberRow.RequireGender = nfmMembers.RequireGender; familyMemberRow.RequireGrade = nfmMembers.RequireGrade; familyMemberRow.RoleId = familyMember.GroupRoleId; familyMemberRow.ShowGrade = familyMember.GroupRoleId == _childRoleId; familyMemberRow.ValidationGroup = BlockValidationGroup; var contactInfoRow = new NewFamilyContactInfoRow(); nfciContactInfo.Controls.Add( contactInfoRow ); contactInfoRow.ID = string.Format( "ci_row_{0}", familyMemberGuidString ); contactInfoRow.PersonGuid = familyMember.Person.Guid; contactInfoRow.IsMessagingEnabled = _SMSEnabled; contactInfoRow.PersonName = familyMember.Person.FullName; if ( _homePhone != null ) { var homePhoneNumber = familyMember.Person.PhoneNumbers.Where( p => p.NumberTypeValueId == _homePhone.Id ).FirstOrDefault(); if ( homePhoneNumber != null ) { contactInfoRow.HomePhoneNumber = PhoneNumber.FormattedNumber( homePhoneNumber.CountryCode, homePhoneNumber.Number ); contactInfoRow.HomePhoneCountryCode = homePhoneNumber.CountryCode; } } if ( _cellPhone != null ) { var cellPhoneNumber = familyMember.Person.PhoneNumbers.Where( p => p.NumberTypeValueId == _cellPhone.Id ).FirstOrDefault(); if ( cellPhoneNumber != null ) { contactInfoRow.CellPhoneNumber = PhoneNumber.FormattedNumber( cellPhoneNumber.CountryCode, cellPhoneNumber.Number ); contactInfoRow.CellPhoneCountryCode = cellPhoneNumber.CountryCode; } } contactInfoRow.Email = familyMember.Person.Email; if ( setSelection ) { if ( familyMember.Person != null ) { familyMemberRow.TitleValueId = familyMember.Person.TitleValueId; familyMemberRow.FirstName = familyMember.Person.FirstName; familyMemberRow.LastName = familyMember.Person.LastName; familyMemberRow.SuffixValueId = familyMember.Person.SuffixValueId; familyMemberRow.Gender = familyMember.Person.Gender; familyMemberRow.BirthDate = familyMember.Person.BirthDate; familyMemberRow.ConnectionStatusValueId = familyMember.Person.ConnectionStatusValueId; familyMemberRow.GradeOffset = familyMember.Person.GradeOffset; } } foreach ( var attributeControl in attributeControls ) { var attributeRow = new NewFamilyAttributesRow(); attributeControl.Controls.Add( attributeRow ); attributeRow.ID = string.Format( "{0}_{1}", attributeControl.ID, familyMemberGuidString ); attributeRow.AttributeList = attributeControl.AttributeList; attributeRow.PersonGuid = familyMember.Person.Guid; attributeRow.PersonName = familyMember.Person.FullName; if ( setSelection ) { attributeRow.SetEditValues( familyMember.Person ); } } if ( Duplicates.ContainsKey( familyMember.Person.Guid ) ) { var dupRow = new HtmlGenericControl( "div" ); dupRow.AddCssClass( "row" ); dupRow.ID = string.Format( "dupRow_{0}", familyMemberGuidString ); phDuplicates.Controls.Add( dupRow ); var newPersonCol = new HtmlGenericControl( "div" ); newPersonCol.AddCssClass( "col-md-6" ); newPersonCol.ID = string.Format( "newPersonCol_{0}", familyMemberGuidString ); dupRow.Controls.Add( newPersonCol ); newPersonCol.Controls.Add( PersonHtmlPanel( familyMemberGuidString, familyMember.Person, familyMember.GroupRole, location, rockContext ) ); LinkButton lbRemoveMember = new LinkButton(); lbRemoveMember.ID = string.Format( "lbRemoveMember_{0}", familyMemberGuidString ); lbRemoveMember.AddCssClass( "btn btn-danger btn-xs" ); lbRemoveMember.Text = "Remove"; lbRemoveMember.Click += lbRemoveMember_Click; newPersonCol.Controls.Add( lbRemoveMember ); var dupPersonCol = new HtmlGenericControl( "div" ); dupPersonCol.AddCssClass( "col-md-6" ); dupPersonCol.ID = string.Format( "dupPersonCol_{0}", familyMemberGuidString ); dupRow.Controls.Add( dupPersonCol ); var duplicateHeader = new HtmlGenericControl( "h4" ); duplicateHeader.InnerText = "Possible Duplicate Records"; dupPersonCol.Controls.Add( duplicateHeader ); foreach ( var duplicate in Duplicates[familyMember.Person.Guid] ) { GroupTypeRole groupTypeRole = null; Location duplocation = null; var familyGroupMember = groupMemberService.Queryable() .Where( a => a.PersonId == duplicate.Id ) .Where( a => a.Group.GroupTypeId == familyGroupType.Id ) .Select( s => new { s.GroupRole, GroupLocation = s.Group.GroupLocations.Where( a => a.GroupLocationTypeValue.Guid == homeLocationGuid ).Select( a => a.Location ).FirstOrDefault() } ) .FirstOrDefault(); if ( familyGroupMember != null ) { groupTypeRole = familyGroupMember.GroupRole; duplocation = familyGroupMember.GroupLocation; } dupPersonCol.Controls.Add( PersonHtmlPanel( familyMemberGuidString, duplicate, groupTypeRole, duplocation, rockContext ) ); } } } ShowPage(); }