public GetPersonIdsByHomeAddress ( string partialHomeAddress ) : IQueryable |
||
partialHomeAddress | string | a partial address search string |
return | IQueryable |
private void BindGrid() { var birthDateCol = gPeople.ColumnsOfType<DateField>().First( c => c.DataField == "BirthDate" ); birthDateCol.Visible = GetAttributeValue( "ShowBirthdate" ).AsBoolean(); string type = PageParameter( "SearchType" ); string term = PageParameter( "SearchTerm" ); if ( !string.IsNullOrWhiteSpace( type ) && !string.IsNullOrWhiteSpace( term ) ) { term = term.Trim(); type = type.Trim(); var rockContext = new RockContext(); var personService = new PersonService( rockContext ); IQueryable<Person> people = null; switch ( type.ToLower() ) { case ( "name" ): { bool allowFirstNameOnly = false; if ( !bool.TryParse( PageParameter( "allowFirstNameOnly" ), out allowFirstNameOnly ) ) { allowFirstNameOnly = false; } people = personService.GetByFullName( term, allowFirstNameOnly, true ); break; } case ( "phone" ): { var phoneService = new PhoneNumberService( rockContext ); var personIds = phoneService.GetPersonIdsByNumber( term ); people = personService.Queryable().Where( p => personIds.Contains( p.Id ) ); break; } case ( "address" ): { var groupMemberService = new GroupMemberService( rockContext ); var personIds2 = groupMemberService.GetPersonIdsByHomeAddress( term ); people = personService.Queryable().Where( p => personIds2.Contains( p.Id ) ); break; } case ( "email" ): { people = personService.Queryable().Where( p => p.Email.Contains( term ) ); break; } } var personIdList = people.Select( p => p.Id ).ToList(); people = personService.Queryable(true).Where( p => personIdList.Contains( p.Id ) ); SortProperty sortProperty = gPeople.SortProperty; if ( sortProperty != null ) { people = people.Sort( sortProperty ); } else { people = people.OrderBy( p => p.LastName ).ThenBy( p => p.FirstName ); } Guid familyGuid = new Guid( Rock.SystemGuid.GroupType.GROUPTYPE_FAMILY ); Guid homeAddressTypeGuid = new Guid( Rock.SystemGuid.DefinedValue.GROUP_LOCATION_TYPE_HOME ); var personList = people.Select( p => new PersonSearchResult { Id = p.Id, FirstName = p.FirstName, NickName = p.NickName, LastName = p.LastName, BirthDate = p.BirthDate, BirthYear = p.BirthYear, BirthMonth = p.BirthMonth, BirthDay = p.BirthDay, ConnectionStatusValueId = p.ConnectionStatusValueId, RecordStatusValueId = p.RecordStatusValueId, RecordTypeValueId = p.RecordTypeValueId, SuffixValueId = p.SuffixValueId, IsDeceased = p.IsDeceased, Email = p.Email, Gender = p.Gender, PhotoId = p.PhotoId, CampusIds = p.Members .Where( m => m.Group.GroupType.Guid.Equals( familyGuid ) && m.Group.CampusId.HasValue ) .Select( m => m.Group.CampusId.Value ) .ToList(), HomeAddresses = p.Members .Where( m => m.Group.GroupType.Guid == familyGuid ) .SelectMany( m => m.Group.GroupLocations ) .Where( gl => gl.GroupLocationTypeValue.Guid.Equals( homeAddressTypeGuid ) ) .Select( gl => gl.Location ) } ).ToList(); if ( personList.Count == 1 ) { Response.Redirect( string.Format( "~/Person/{0}", personList[0].Id ), false ); Context.ApplicationInstance.CompleteRequest(); } else { if ( type.ToLower() == "name" ) { var similarNames = personService.GetSimilarNames( term, personList.Select( p => p.Id ).ToList(), true ); if ( similarNames.Any() ) { var hyperlinks = new List<string>(); foreach ( string name in similarNames.Distinct() ) { var pageRef = CurrentPageReference; pageRef.Parameters["SearchTerm"] = name; hyperlinks.Add( string.Format( "<a href='{0}'>{1}</a>", pageRef.BuildUrl(), name ) ); } string altNames = string.Join( ", ", hyperlinks ); nbNotice.Text = string.Format( "Other Possible Matches: {0}", altNames ); nbNotice.Visible = true; } } _inactiveStatus = DefinedValueCache.Read( Rock.SystemGuid.DefinedValue.PERSON_RECORD_STATUS_INACTIVE ); gPeople.EntityTypeId = EntityTypeCache.GetId<Person>(); gPeople.DataSource = personList; gPeople.DataBind(); } } }
private void BindGrid() { string type = PageParameter( "SearchType" ); string term = PageParameter( "SearchTerm" ); if ( !String.IsNullOrWhiteSpace( type ) && !String.IsNullOrWhiteSpace( term ) ) { var rockContext = new RockContext(); var personService = new PersonService( rockContext ); IQueryable<Person> people = null; switch ( type.ToLower() ) { case ( "name" ): { bool allowFirstNameOnly = false; if ( !bool.TryParse( PageParameter( "allowFirstNameOnly" ), out allowFirstNameOnly ) ) { allowFirstNameOnly = false; } people = personService.GetByFullName( term, allowFirstNameOnly, true ); break; } case ( "phone" ): { var phoneService = new PhoneNumberService( rockContext ); var personIds = phoneService.GetPersonIdsByNumber( term ); people = personService.Queryable().Where( p => personIds.Contains( p.Id ) ); break; } case ( "address" ): { var groupMemberService = new GroupMemberService( rockContext ); var personIds2 = groupMemberService.GetPersonIdsByHomeAddress( term ); people = personService.Queryable().Where( p => personIds2.Contains( p.Id ) ); break; } case ( "email" ): { people = personService.Queryable().Where( p => p.Email.Contains( term ) ); break; } } SortProperty sortProperty = gPeople.SortProperty; if ( sortProperty != null ) { people = people.Sort( sortProperty ); } else { people = people.OrderBy( p => p.LastName ).ThenBy( p => p.FirstName ); } var personList = people.ToList(); if ( personList.Count == 1 ) { Response.Redirect( string.Format( "~/Person/{0}", personList[0].Id ), false ); Context.ApplicationInstance.CompleteRequest(); } else { if ( type.ToLower() == "name" ) { var similiarNames = personService.GetSimiliarNames( term, personList.Select( p => p.Id ).ToList(), true ); if ( similiarNames.Any() ) { var hyperlinks = new List<string>(); foreach ( string name in similiarNames.Distinct() ) { var pageRef = CurrentPageReference; pageRef.Parameters["SearchTerm"] = name; hyperlinks.Add( string.Format( "<a href='{0}'>{1}</a>", pageRef.BuildUrl(), name ) ); } string altNames = string.Join( ", ", hyperlinks ); nbNotice.Text = string.Format( "Other Possible Matches: {0}", altNames ); nbNotice.Visible = true; } } gPeople.DataSource = personList; gPeople.DataBind(); } } }
private void BindGrid() { string type = PageParameter( "SearchType" ); string term = PageParameter( "SearchTerm" ); List<Person> personList = null; if ( !String.IsNullOrWhiteSpace( type ) && !String.IsNullOrWhiteSpace( term ) ) { using ( var uow = new Rock.Data.UnitOfWorkScope() ) { IQueryable<Person> people = null; var personService = new PersonService(); switch ( type.ToLower() ) { case ( "name" ): people = personService.GetByFullName( term, true ); break; case ( "phone" ): var phoneService = new PhoneNumberService(); var personIds = phoneService.GetPersonIdsByNumber( term ); people = personService.Queryable().Where( p => personIds.Contains( p.Id ) ); break; case ( "address" ): var groupMemberService = new GroupMemberService(); var personIds2 = groupMemberService.GetPersonIdsByHomeAddress( term ); people = personService.Queryable().Where( p => personIds2.Contains( p.Id ) ); break; case ( "email" ): people = personService.Queryable().Where( p => p.Email.Contains( term ) ); break; } SortProperty sortProperty = gPeople.SortProperty; if ( sortProperty != null ) { people = people.Sort( sortProperty ); } else { people = people.OrderBy( p => p.LastName ).ThenBy( p => p.FirstName ); } personList = people.ToList(); } } if ( personList != null ) { if ( personList.Count == 1 ) { Response.Redirect( string.Format( "~/Person/{0}", personList[0].Id ), false ); Context.ApplicationInstance.CompleteRequest(); } else { gPeople.DataSource = personList; gPeople.DataBind(); } } }