本文整理汇总了C#中Rock.Model.PersonService.SplitName方法的典型用法代码示例。如果您正苦于以下问题:C# PersonService.SplitName方法的具体用法?C# PersonService.SplitName怎么用?C# PersonService.SplitName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rock.Model.PersonService
的用法示例。
在下文中一共展示了PersonService.SplitName方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetTwitterUser
/// <summary>
/// Gets the name of the Twitter user.
/// </summary>
/// <param name="twitterUser">The Twitter user.</param>
/// <param name="accessToken">The access token.</param>
/// <returns></returns>
public static string GetTwitterUser( dynamic twitterUser, string accessToken = "" )
{
string username = string.Empty;
string twitterId = twitterUser.id_str;
string twitterLink = "https://twitter.com/" + twitterUser.screen_name;
string userName = "Twitter_" + twitterId;
UserLogin user = null;
using ( var rockContext = new RockContext() )
{
// Query for an existing user
var userLoginService = new UserLoginService( rockContext );
user = userLoginService.GetByUserName( userName );
// If no user was found, see if we can find a match in the person table
if ( user == null )
{
// Get name and email from twitterUser object and then split the name
string fullName = twitterUser.name;
string firstName = null;
string lastName = null;
var personService = new PersonService( rockContext );
personService.SplitName( fullName, out firstName, out lastName );
string email = string.Empty;
try { email = twitterUser.email; }
catch { }
Person person = null;
// If person had an email, get the first person with the same name and email address.
if ( !string.IsNullOrWhiteSpace( email ) )
{
var people = personService.GetByMatch( firstName, lastName, email );
if ( people.Count() == 1 )
{
person = people.First();
}
}
var personRecordTypeId = DefinedValueCache.Read( SystemGuid.DefinedValue.PERSON_RECORD_TYPE_PERSON.AsGuid() ).Id;
var personStatusPending = DefinedValueCache.Read( SystemGuid.DefinedValue.PERSON_RECORD_STATUS_PENDING.AsGuid() ).Id;
rockContext.WrapTransaction( () =>
{
// If not an existing person, create a new one
if ( person == null )
{
person = new Person();
person.IsSystem = false;
person.RecordTypeValueId = personRecordTypeId;
person.RecordStatusValueId = personStatusPending;
person.FirstName = firstName;
person.LastName = lastName;
person.Email = email;
person.IsEmailActive = true;
person.EmailPreference = EmailPreference.EmailAllowed;
person.Gender = Gender.Unknown;
if ( person != null )
{
PersonService.SaveNewPerson( person, rockContext, null, false );
}
}
if ( person != null )
{
int typeId = EntityTypeCache.Read( typeof( Facebook ) ).Id;
user = UserLoginService.Create( rockContext, person, AuthenticationServiceType.External, typeId, userName, "Twitter", true );
}
} );
}
if ( user != null )
{
username = user.UserName;
if ( user.PersonId.HasValue )
{
var converter = new ExpandoObjectConverter();
var personService = new PersonService( rockContext );
var person = personService.Get( user.PersonId.Value );
if ( person != null )
{
string twitterImageUrl = twitterUser.profile_image_url;
bool twitterImageDefault = twitterUser.default_profile_image;
twitterImageUrl = twitterImageUrl.Replace( "_normal", "" );
// If person does not have a photo, use their Twitter photo if it exists
if ( !person.PhotoId.HasValue && !twitterImageDefault && !string.IsNullOrWhiteSpace( twitterImageUrl ) )
{
// Download the photo from the url provided
var restClient = new RestClient( twitterImageUrl );
//.........这里部分代码省略.........