/// <summary> /// Handles the RoleUpdated event of the groupMemberRow control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> /// <exception cref="System.NotImplementedException"></exception> void groupMemberRow_RoleUpdated(object sender, EventArgs e) { NewGroupMembersRow row = sender as NewGroupMembersRow; row.ShowGradePicker = row.RoleId == _childRoleId; row.ShowGradeColumn = _isFamilyGroupType; }
/// <summary> /// Handles the DeleteClick event of the groupMemberRow control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> void groupMemberRow_DeleteClick(object sender, EventArgs e) { NewGroupMembersRow row = sender as NewGroupMembersRow; var groupMember = GroupMembers.FirstOrDefault(m => m.Person.Guid.Equals(row.PersonGuid)); if (groupMember != null) { GroupMembers.Remove(groupMember); } CreateControls(true); }
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 NewGroupAttributes(); attributeControl.ClearRows(); pnlAttributes.Controls.Add(attributeControl); attributeControls.Add(attributeControl); attributeControl.ID = "groupAttributes_" + 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); int defaultRoleId = _groupType.DefaultGroupRoleId ?? _groupType.Roles.Select(r => r.Id).FirstOrDefault(); var location = new Location(); acAddress.GetValues(location); foreach (var groupMember in GroupMembers) { string groupMemberGuidString = groupMember.Person.Guid.ToString().Replace("-", "_"); var groupMemberRow = new NewGroupMembersRow(); groupMemberRow.GroupTypeId = _groupType.Id; nfmMembers.Controls.Add(groupMemberRow); groupMemberRow.ID = string.Format("row_{0}", groupMemberGuidString); groupMemberRow.RoleUpdated += groupMemberRow_RoleUpdated; groupMemberRow.DeleteClick += groupMemberRow_DeleteClick; groupMemberRow.PersonGuid = groupMember.Person.Guid; groupMemberRow.RequireGender = nfmMembers.RequireGender; groupMemberRow.RequireGrade = nfmMembers.RequireGrade; groupMemberRow.RoleId = groupMember.GroupRoleId; groupMemberRow.ShowGradeColumn = _isFamilyGroupType; groupMemberRow.ShowGradePicker = groupMember.GroupRoleId == _childRoleId; groupMemberRow.ValidationGroup = BlockValidationGroup; var contactInfoRow = new NewGroupContactInfoRow(); nfciContactInfo.Controls.Add(contactInfoRow); contactInfoRow.ID = string.Format("ci_row_{0}", groupMemberGuidString); contactInfoRow.PersonGuid = groupMember.Person.Guid; contactInfoRow.IsMessagingEnabled = _SMSEnabled; contactInfoRow.PersonName = groupMember.Person.FullName; if (_homePhone != null) { var homePhoneNumber = groupMember.Person.PhoneNumbers.Where(p => p.NumberTypeValueId == _homePhone.Id).FirstOrDefault(); if (homePhoneNumber != null) { contactInfoRow.HomePhoneNumber = PhoneNumber.FormattedNumber(homePhoneNumber.CountryCode, homePhoneNumber.Number); contactInfoRow.HomePhoneCountryCode = homePhoneNumber.CountryCode; } else { contactInfoRow.HomePhoneNumber = string.Empty; contactInfoRow.HomePhoneCountryCode = string.Empty; } } if (_cellPhone != null) { var cellPhoneNumber = groupMember.Person.PhoneNumbers.Where(p => p.NumberTypeValueId == _cellPhone.Id).FirstOrDefault(); if (cellPhoneNumber != null) { contactInfoRow.CellPhoneNumber = PhoneNumber.FormattedNumber(cellPhoneNumber.CountryCode, cellPhoneNumber.Number); contactInfoRow.CellPhoneCountryCode = cellPhoneNumber.CountryCode; } else { contactInfoRow.CellPhoneNumber = string.Empty; contactInfoRow.CellPhoneCountryCode = string.Empty; } } contactInfoRow.Email = groupMember.Person.Email; if (setSelection) { if (groupMember.Person != null) { groupMemberRow.TitleValueId = groupMember.Person.TitleValueId; groupMemberRow.FirstName = groupMember.Person.FirstName; groupMemberRow.LastName = groupMember.Person.LastName; groupMemberRow.SuffixValueId = groupMember.Person.SuffixValueId; groupMemberRow.Gender = groupMember.Person.Gender; groupMemberRow.BirthDate = groupMember.Person.BirthDate; groupMemberRow.ConnectionStatusValueId = groupMember.Person.ConnectionStatusValueId; groupMemberRow.GradeOffset = groupMember.Person.GradeOffset; } } foreach (var attributeControl in attributeControls) { var attributeRow = new NewGroupAttributesRow(); attributeControl.Controls.Add(attributeRow); attributeRow.ID = string.Format("{0}_{1}", attributeControl.ID, groupMemberGuidString); attributeRow.AttributeList = attributeControl.AttributeList; attributeRow.PersonGuid = groupMember.Person.Guid; attributeRow.PersonName = groupMember.Person.FullName; if (setSelection) { attributeRow.SetEditValues(groupMember.Person); } } if (Duplicates.ContainsKey(groupMember.Person.Guid)) { var dupRow = new HtmlGenericControl("div"); dupRow.AddCssClass("row"); dupRow.ID = string.Format("dupRow_{0}", groupMemberGuidString); phDuplicates.Controls.Add(dupRow); var newPersonCol = new HtmlGenericControl("div"); newPersonCol.AddCssClass("col-md-6"); newPersonCol.ID = string.Format("newPersonCol_{0}", groupMemberGuidString); dupRow.Controls.Add(newPersonCol); newPersonCol.Controls.Add(PersonHtmlPanel( groupMemberGuidString, groupMember.Person, groupMember.GroupRole, location, rockContext)); LinkButton lbRemoveMember = new LinkButton(); lbRemoveMember.ID = string.Format("lbRemoveMember_{0}", groupMemberGuidString); 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}", groupMemberGuidString); dupRow.Controls.Add(dupPersonCol); var duplicateHeader = new HtmlGenericControl("h4"); duplicateHeader.InnerText = "Possible Duplicate Records"; dupPersonCol.Controls.Add(duplicateHeader); foreach (var duplicate in Duplicates[groupMember.Person.Guid]) { GroupTypeRole groupTypeRole = null; Location duplocation = null; var dupGroupMember = groupMemberService.Queryable() .Where(a => a.PersonId == duplicate.Id) .Where(a => a.Group.GroupTypeId == _groupType.Id) .Select(s => new { s.GroupRole, GroupLocation = s.Group.GroupLocations.Where(a => a.GroupLocationTypeValue.Guid.Equals(_locationType.Guid)).Select(a => a.Location).FirstOrDefault() }) .FirstOrDefault(); if (dupGroupMember != null) { groupTypeRole = dupGroupMember.GroupRole; duplocation = dupGroupMember.GroupLocation; } dupPersonCol.Controls.Add(PersonHtmlPanel( groupMemberGuidString, duplicate, groupTypeRole, duplocation, rockContext)); } } } ShowPage(); }