当前位置: 首页>>代码示例>>C#>>正文


C# PersonService.GetSimilarNames方法代码示例

本文整理汇总了C#中Rock.Model.PersonService.GetSimilarNames方法的典型用法代码示例。如果您正苦于以下问题:C# PersonService.GetSimilarNames方法的具体用法?C# PersonService.GetSimilarNames怎么用?C# PersonService.GetSimilarNames使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Rock.Model.PersonService的用法示例。


在下文中一共展示了PersonService.GetSimilarNames方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BindGrid


//.........这里部分代码省略.........
                            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();
                }
            }
        }
开发者ID:,项目名称:,代码行数:101,代码来源:


注:本文中的Rock.Model.PersonService.GetSimilarNames方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。