本文整理汇总了C#中Rock.Model.PersonService.GetSimiliarNames方法的典型用法代码示例。如果您正苦于以下问题:C# PersonService.GetSimiliarNames方法的具体用法?C# PersonService.GetSimiliarNames怎么用?C# PersonService.GetSimiliarNames使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rock.Model.PersonService
的用法示例。
在下文中一共展示了PersonService.GetSimiliarNames方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BindGrid
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();
}
}
}
示例2: BindGrid
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 );
}
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 similiarNames = personService.GetSimiliarNames( term,
personList.Select( p => p.Id ).ToList(), true );
//.........这里部分代码省略.........