/// <summary> /// Gets the expression. /// </summary> /// <param name="context">The context.</param> /// <param name="entityIdProperty">The entity identifier property.</param> /// <param name="selection">The selection.</param> /// <returns></returns> public override Expression GetExpression(RockContext context, MemberExpression entityIdProperty, string selection) { string[] values = selection.Split('|'); Guid groupLocationTypeValueGuid = Rock.SystemGuid.DefinedValue.GROUP_LOCATION_TYPE_HOME.AsGuid(); RockUdfHelper.AddressNamePart addressNamePart = RockUdfHelper.AddressNamePart.Full; if (values.Length >= 1) { groupLocationTypeValueGuid = values[0].AsGuidOrNull() ?? Rock.SystemGuid.DefinedValue.GROUP_LOCATION_TYPE_HOME.AsGuid(); } if (values.Length >= 2) { addressNamePart = values[1].ConvertToEnumOrNull <RockUdfHelper.AddressNamePart>() ?? RockUdfHelper.AddressNamePart.Full; } string addressTypeId = DefinedValueCache.Get(groupLocationTypeValueGuid).Id.ToString(); string addressComponent = addressNamePart.ConvertToString(false); var personLocationQuery = new PersonService(context).Queryable() .Select(p => RockUdfHelper.ufnCrm_GetAddress(p.Id, addressTypeId, addressComponent)); return(SelectExpressionExtractor.Extract(personLocationQuery, entityIdProperty, "p")); }
private void BindGrid() { var rockContext = new RockContext(); var groupMemberService = new GroupMemberService(rockContext).Queryable().AsNoTracking(); List <int> groupIdsMulti = gpGroups.SelectedValuesAsInt().ToList(); var groupMembers = groupMemberService.Where(gm => groupIdsMulti.Contains(gm.GroupId)); SortProperty sortProperty = groupMemberGrid.SortProperty; groupMembers = FilterByBirthday(groupMembers); Guid groupLocationTypeValueGuid = Rock.SystemGuid.DefinedValue.GROUP_LOCATION_TYPE_HOME.AsGuid(); RockUdfHelper.AddressNamePart addressNamePart = RockUdfHelper.AddressNamePart.Full; string addressTypeId = DefinedValueCache.Get(groupLocationTypeValueGuid).Id.ToString(); string addressComponent = addressNamePart.ConvertToString(false); if (sortProperty != null) { groupMemberGrid.DataSource = groupMembers.Select(gm => new MemberData() { FirstName = gm.Person.FirstName, LastName = gm.Person.LastName, Id = gm.Person.Id, BirthMonth = gm.Person.BirthMonth, BirthDay = gm.Person.BirthDay, BirthYear = gm.Person.BirthYear, Birthdate = gm.Person.BirthDate, AnniversaryMonth = gm.Person.AnniversaryDate.HasValue ? gm.Person.AnniversaryDate.Value.Month : (int?)null, AnniversaryDay = gm.Person.AnniversaryDate.HasValue ? gm.Person.AnniversaryDate.Value.Day : (int?)null, AnniversaryYear = gm.Person.AnniversaryDate.HasValue ? gm.Person.AnniversaryDate.Value.Year : (int?)null, Anniversary = gm.Person.AnniversaryDate, Email = gm.Person.Email, Address = RockUdfHelper.ufnCrm_GetAddress(gm.Person.Id, addressTypeId, addressComponent) }).Distinct().Sort(sortProperty).ToList(); } else { groupMemberGrid.DataSource = groupMembers.Select(gm => new MemberData() { FirstName = gm.Person.FirstName, LastName = gm.Person.LastName, Id = gm.Person.Id, BirthMonth = gm.Person.BirthMonth, BirthDay = gm.Person.BirthDay, BirthYear = gm.Person.BirthYear, Birthdate = gm.Person.BirthDate, AnniversaryMonth = gm.Person.AnniversaryDate.HasValue ? gm.Person.AnniversaryDate.Value.Month : (int?)null, AnniversaryDay = gm.Person.AnniversaryDate.HasValue ? gm.Person.AnniversaryDate.Value.Day : (int?)null, AnniversaryYear = gm.Person.AnniversaryDate.HasValue ? gm.Person.AnniversaryDate.Value.Year : (int?)null, Anniversary = gm.Person.AnniversaryDate, Email = gm.Person.Email, Address = RockUdfHelper.ufnCrm_GetAddress(gm.Person.Id, addressTypeId, addressComponent) }).Distinct().OrderBy(s => s.FirstName).ToList(); } groupMemberGrid.DataBind(); }