private List <FamilyMember> GetMembersOrdered() { var orderedMembers = new List <FamilyMember>(); // Add adult males orderedMembers.AddRange(FamilyMembers .Where(m => !m.Removed && m.RoleGuid.Equals(new Guid(Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_ADULT)) && m.Gender == Gender.Male) .OrderByDescending(m => m.Age)); // Add adult females orderedMembers.AddRange(FamilyMembers .Where(m => !m.Removed && m.RoleGuid.Equals(new Guid(Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_ADULT)) && m.Gender != Gender.Male) .OrderByDescending(m => m.Age)); // Add non-adults orderedMembers.AddRange(FamilyMembers .Where(m => !m.Removed && !m.RoleGuid.Equals(new Guid(Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_ADULT))) .OrderByDescending(m => m.Age)); return(orderedMembers); }
/// <summary> /// Raises the <see cref="E:System.Web.UI.Control.PreRender" /> event. /// </summary> /// <param name="e">An <see cref="T:System.EventArgs" /> object that contains the event data.</param> protected override void OnPreRender(EventArgs e) { var adults = FamilyMembers.Where(m => m.GroupRoleId != _childRoleId).ToList(); ddlMaritalStatus.Visible = adults.Any(); base.OnPreRender(e); }
/// <summary> /// Raises the <see cref="E:System.Web.UI.Control.Load" /> event. /// </summary> /// <param name="e">The <see cref="T:System.EventArgs" /> object that contains the event data.</param> protected override void OnLoad(EventArgs e) { base.OnLoad(e); if (Page.IsPostBack) { foreach (var item in lvMembers.Items) { var rblRole = item.FindControl("rblRole") as RadioButtonList; if (rblRole != null) { int?roleId = rblRole.SelectedValueAsInt(); if (roleId.HasValue) { var role = familyRoles.Where(r => r.Id == roleId.Value).FirstOrDefault(); if (role != null) { int index = (int)lvMembers.DataKeys[item.DataItemIndex]["Index"]; var familyMember = FamilyMembers.Where(m => m.Index == index).FirstOrDefault(); if (familyMember != null) { familyMember.RoleGuid = role.Guid; familyMember.RoleName = role.Name; } } } } } } else { if (_family != null) { tbFamilyName.Text = _family.Name; cpCampus.SelectedCampusId = _family.CampusId; FamilyMembers = new List <FamilyMember>(); foreach (var familyMember in _family.Members) { FamilyMembers.Add(new FamilyMember(familyMember, true)); } BindMembers(); FamilyAddresses = new List <FamilyAddress>(); foreach (var groupLocation in _family.GroupLocations) { FamilyAddresses.Add(new FamilyAddress(groupLocation)); } BindLocations(); } } }
/// <summary> /// Handles the ItemDataBound event of the lvMembers control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="ListViewItemEventArgs"/> instance containing the event data.</param> /// <exception cref="System.NotImplementedException"></exception> void lvMembers_ItemDataBound(object sender, ListViewItemEventArgs e) { if (e.Item.ItemType == ListViewItemType.DataItem) { var familyMember = e.Item.DataItem as FamilyMember; if (familyMember != null) { System.Web.UI.WebControls.Image imgPerson = e.Item.FindControl("imgPerson") as System.Web.UI.WebControls.Image; if (imgPerson != null) { imgPerson.Visible = familyMember.PhotoId.HasValue; if (familyMember.PhotoId.HasValue) { imgPerson.ImageUrl = string.Format("~/GetImage.ashx?id={0}", familyMember.PhotoId); } } var rblRole = e.Item.FindControl("rblRole") as RadioButtonList; if (rblRole != null) { rblRole.DataSource = familyRoles; rblRole.DataBind(); var role = familyRoles.Where(r => r.Guid.Equals(familyMember.RoleGuid)).FirstOrDefault(); if (role != null) { rblRole.SelectedValue = role.Id.ToString(); } } int members = FamilyMembers.Where(m => !m.Removed).Count(); var lbNewFamily = e.Item.FindControl("lbNewFamily") as LinkButton; if (lbNewFamily != null) { lbNewFamily.Visible = familyMember.ExistingFamilyMember && members > 1; } var lbRemoveMember = e.Item.FindControl("lbRemoveMember") as LinkButton; if (lbRemoveMember != null) { lbRemoveMember.Visible = !familyMember.ExistingFamilyMember && members > 1; } } } }
void lbRemoveMember_Click(object sender, EventArgs e) { Guid personGuid = ((LinkButton)sender).ID.Substring(15).Replace("_", "-").AsGuid(); var familyMember = FamilyMembers.Where(f => f.Person.Guid.Equals(personGuid)).FirstOrDefault(); if (familyMember != null) { FamilyMembers.Remove(familyMember); Duplicates.Remove(personGuid); if (!FamilyMembers.Any()) { AddFamilyMember(); CurrentPageIndex = 0; } CreateControls(true); } }
/// <summary> /// Handles the ItemCommand event of the lvMembers control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="ListViewCommandEventArgs"/> instance containing the event data.</param> void lvMembers_ItemCommand(object sender, ListViewCommandEventArgs e) { int index = (int)lvMembers.DataKeys[e.Item.DataItemIndex]["Index"]; var familyMember = FamilyMembers.Where(m => m.Index == index).FirstOrDefault(); if (familyMember != null) { if (e.CommandName == "Move") { familyMember.Removed = true; } else if (e.CommandName == "Remove") { FamilyMembers.RemoveAt(index); } confirmExit.Enabled = true; BindMembers(); } }
public bool FindDuplicates() { Duplicates = new Dictionary <Guid, List <Person> >(); var rockContext = new RockContext(); var locationService = new LocationService(rockContext); var groupService = new GroupService(rockContext); var personService = new PersonService(rockContext); // Find any other family members (any family) that have same location var othersAtAddress = new List <int>(); var familyGroupType = GroupTypeCache.GetFamilyGroupType(); var location = locationService.Get(acAddress.Street1, acAddress.Street2, acAddress.City, acAddress.State, acAddress.PostalCode, acAddress.Country); if (location != null) { othersAtAddress = groupService .Queryable().AsNoTracking() .Where(g => g.GroupTypeId == familyGroupType.Id && g.GroupLocations.Any(l => l.LocationId == location.Id)) .SelectMany(g => g.Members) .Select(m => m.PersonId) .ToList(); } foreach (var person in FamilyMembers .Where(m => m.Person != null && m.Person.FirstName != "") .Select(m => m.Person)) { bool otherCriteria = false; var personQry = personService .Queryable().AsNoTracking() .Where(p => p.FirstName == person.FirstName || p.NickName == person.FirstName); if (othersAtAddress.Any()) { personQry = personQry .Where(p => othersAtAddress.Contains(p.Id)); } if (person.BirthDate.HasValue) { otherCriteria = true; personQry = personQry .Where(p => p.BirthDate.HasValue && p.BirthDate.Value == person.BirthDate.Value); } if (_homePhone != null) { var homePhoneNumber = person.PhoneNumbers.Where(p => p.NumberTypeValueId == _homePhone.Id).FirstOrDefault(); if (homePhoneNumber != null) { otherCriteria = true; personQry = personQry .Where(p => p.PhoneNumbers.Any(n => n.NumberTypeValueId == _homePhone.Id && n.Number == homePhoneNumber.Number)); } } if (_cellPhone != null) { var cellPhoneNumber = person.PhoneNumbers.Where(p => p.NumberTypeValueId == _cellPhone.Id).FirstOrDefault(); if (cellPhoneNumber != null) { otherCriteria = true; personQry = personQry .Where(p => p.PhoneNumbers.Any(n => n.NumberTypeValueId == _cellPhone.Id && n.Number == cellPhoneNumber.Number)); } } if (!string.IsNullOrWhiteSpace(person.Email)) { otherCriteria = true; personQry = personQry .Where(p => p.Email == person.Email); } var dups = new List <Person>(); if (otherCriteria) { // If a birthday, email, phone, or address was entered, find anyone with same info and same first name dups = personQry.ToList(); } else { // otherwise find people with same first and last name dups = personQry .Where(p => p.LastName == person.LastName) .ToList(); } if (dups.Any()) { Duplicates.Add(person.Guid, dups); } } return(Duplicates.Any()); }