本文整理汇总了C#中Rock.Model.PersonAliasService.Queryable方法的典型用法代码示例。如果您正苦于以下问题:C# PersonAliasService.Queryable方法的具体用法?C# PersonAliasService.Queryable怎么用?C# PersonAliasService.Queryable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rock.Model.PersonAliasService
的用法示例。
在下文中一共展示了PersonAliasService.Queryable方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: gFollowings_Delete
/// <summary>
/// Handles the Delete event of the gFollowings control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="RowEventArgs" /> instance containing the event data.</param>
protected void gFollowings_Delete( object sender, RowEventArgs e )
{
var rockContext = new RockContext();
var personAliasService = new PersonAliasService( rockContext );
var followingService = new FollowingService( rockContext );
var paQry = personAliasService.Queryable()
.Where( p => p.PersonId == e.RowKeyId )
.Select( p => p.Id );
int personAliasEntityTypeId = EntityTypeCache.Read( "Rock.Model.PersonAlias" ).Id;
foreach ( var following in followingService.Queryable()
.Where( f =>
f.EntityTypeId == personAliasEntityTypeId &&
paQry.Contains( f.EntityId ) &&
f.PersonAliasId == CurrentPersonAlias.Id ) )
{
followingService.Delete( following );
}
rockContext.SaveChanges();
BindGrid();
}
示例2: btnConfirm_Click
/// <summary>
/// Handles the Click event of the btnConfirm control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
protected void btnConfirm_Click( object sender, EventArgs e )
{
if ( Page.IsValid )
{
var rockContext = new RockContext();
var personService = new PersonService( rockContext );
var ids = Individuals.Select( i => i.PersonId ).ToList();
#region Individual Details Updates
int? newTitleId = ddlTitle.SelectedValueAsInt();
int? newSuffixId = ddlSuffix.SelectedValueAsInt();
int? newConnectionStatusId = ddlStatus.SelectedValueAsInt();
int? newRecordStatusId = ddlRecordStatus.SelectedValueAsInt();
int? newInactiveReasonId = ddlInactiveReason.SelectedValueAsInt();
string newInactiveReasonNote = tbInactiveReasonNote.Text;
Gender newGender = ddlGender.SelectedValue.ConvertToEnum<Gender>();
int? newMaritalStatusId = ddlMaritalStatus.SelectedValueAsInt();
int? newGraduationYear = null;
if ( ypGraduation.SelectedYear.HasValue )
{
newGraduationYear = ypGraduation.SelectedYear.Value;
}
int? newCampusId = cpCampus.SelectedCampusId;
bool? newEmailActive = null;
if ( !string.IsNullOrWhiteSpace( ddlIsEmailActive.SelectedValue ) )
{
newEmailActive = ddlIsEmailActive.SelectedValue == "Active";
}
EmailPreference? newEmailPreference = ddlEmailPreference.SelectedValue.ConvertToEnumOrNull<EmailPreference>();
string newEmailNote = tbEmailNote.Text;
int? newReviewReason = ddlReviewReason.SelectedValueAsInt();
string newSystemNote = tbSystemNote.Text;
string newReviewReasonNote = tbReviewReasonNote.Text;
int inactiveStatusId = DefinedValueCache.Read( Rock.SystemGuid.DefinedValue.PERSON_RECORD_STATUS_INACTIVE ).Id;
var allChanges = new Dictionary<int, List<string>>();
var people = personService.Queryable().Where( p => ids.Contains( p.Id ) ).ToList();
foreach ( var person in people )
{
var changes = new List<string>();
allChanges.Add( person.Id, changes );
if ( SelectedFields.Contains( ddlTitle.ClientID ) )
{
History.EvaluateChange( changes, "Title", DefinedValueCache.GetName( person.TitleValueId ), DefinedValueCache.GetName( newTitleId ) );
person.TitleValueId = newTitleId;
}
if ( SelectedFields.Contains( ddlSuffix.ClientID ) )
{
History.EvaluateChange( changes, "Suffix", DefinedValueCache.GetName( person.SuffixValueId ), DefinedValueCache.GetName( newSuffixId ) );
person.SuffixValueId = newSuffixId;
}
if ( SelectedFields.Contains( ddlStatus.ClientID ) )
{
History.EvaluateChange( changes, "Connection Status", DefinedValueCache.GetName( person.ConnectionStatusValueId ), DefinedValueCache.GetName( newConnectionStatusId ) );
person.ConnectionStatusValueId = newConnectionStatusId;
}
if ( SelectedFields.Contains( ddlRecordStatus.ClientID ) )
{
History.EvaluateChange( changes, "Record Status", DefinedValueCache.GetName( person.RecordStatusValueId ), DefinedValueCache.GetName( newRecordStatusId ) );
person.RecordStatusValueId = newRecordStatusId;
if ( newRecordStatusId.HasValue && newRecordStatusId.Value == inactiveStatusId )
{
History.EvaluateChange( changes, "Inactive Reason", DefinedValueCache.GetName( person.RecordStatusReasonValueId ), DefinedValueCache.GetName( newInactiveReasonId ) );
person.RecordStatusReasonValueId = newInactiveReasonId;
if ( !string.IsNullOrWhiteSpace( newInactiveReasonNote ) )
{
History.EvaluateChange( changes, "Inactive Reason Note", person.InactiveReasonNote, newInactiveReasonNote );
person.InactiveReasonNote = newInactiveReasonNote;
}
}
}
if ( SelectedFields.Contains( ddlGender.ClientID ) )
{
History.EvaluateChange( changes, "Gender", person.Gender, newGender );
person.Gender = newGender;
}
if ( SelectedFields.Contains( ddlMaritalStatus.ClientID ) )
{
//.........这里部分代码省略.........
示例3: AddFamilies
//.........这里部分代码省略.........
{
// Put the person's id into the people dictionary for later use.
if ( !_peopleDictionary.ContainsKey( gm.Person.Guid ) )
{
_peopleDictionary.Add( gm.Person.Guid, gm.Person.Id );
}
// Only save if the person had attributes, otherwise it will error.
if ( _personWithAttributes.ContainsKey( gm.Person.Guid ) )
{
foreach ( var attributeCache in gm.Person.Attributes.Select( a => a.Value ) )
{
var newValue = gm.Person.AttributeValues[attributeCache.Key];
if ( newValue != null )
{
var attributeValue = new AttributeValue();
attributeValue.AttributeId = newValue.AttributeId;
attributeValue.EntityId = gm.Person.Id;
attributeValue.Value = newValue.Value;
rockContext.AttributeValues.Add( attributeValue );
}
}
}
}
rockContext.ChangeTracker.DetectChanges();
rockContext.SaveChanges( disablePrePostProcessing: true );
_stopwatch.Stop();
AppendFormat( "{0:00}:{1:00}.{2:00} attributes saved<br/>", _stopwatch.Elapsed.Minutes, _stopwatch.Elapsed.Seconds, _stopwatch.Elapsed.Milliseconds / 10 );
_stopwatch.Start();
// Create person alias records for each person manually since we set disablePrePostProcessing=true on save
PersonService personService = new PersonService( rockContext );
foreach ( var person in personService.Queryable( "Aliases", true )
.Where( p =>
_peopleDictionary.Keys.Contains( p.Guid ) &&
!p.Aliases.Any() ) )
{
person.Aliases.Add( new PersonAlias { AliasPersonId = person.Id, AliasPersonGuid = person.Guid } );
}
rockContext.ChangeTracker.DetectChanges();
rockContext.SaveChanges( disablePrePostProcessing: true );
_stopwatch.Stop();
AppendFormat( "{0:00}:{1:00}.{2:00} added person aliases<br/>", _stopwatch.Elapsed.Minutes, _stopwatch.Elapsed.Seconds, _stopwatch.Elapsed.Milliseconds / 10 );
_stopwatch.Start();
// Put the person alias ids into the people alias dictionary for later use.
PersonAliasService personAliasService = new PersonAliasService( rockContext );
foreach ( var personAlias in personAliasService.Queryable( "Person" )
.Where( a =>
_peopleDictionary.Keys.Contains( a.Person.Guid ) &&
a.PersonId == a.AliasPersonId ) )
{
_peopleAliasDictionary.Add( personAlias.Person.Guid, personAlias.Id );
}
// Now that person aliases have been saved, save the attendance records
var attendanceService = new AttendanceService( rockContext );
var attendanceGuids = attendanceData.Select( a => a.Key ).ToList();
foreach ( var aliasKeyValue in _peopleAliasDictionary
.Where( a => attendanceGuids.Contains( a.Key )) )
{
foreach ( var attendance in attendanceData[aliasKeyValue.Key] )
{
attendance.PersonAliasId = aliasKeyValue.Value;
示例4: DeleteExistingFamilyData
/// <summary>
/// Deletes the family's addresses, phone numbers, photos, viewed records, and people.
/// TODO: delete attendance codes for attendance data that's about to be deleted when
/// we delete the person record.
/// </summary>
/// <param name="families">The families.</param>
/// <param name="rockContext">The rock context.</param>
private void DeleteExistingFamilyData( XElement families, RockContext rockContext )
{
PersonService personService = new PersonService( rockContext );
PhoneNumberService phoneNumberService = new PhoneNumberService( rockContext );
PersonViewedService personViewedService = new PersonViewedService( rockContext );
PageViewService pageViewService = new PageViewService( rockContext );
BinaryFileService binaryFileService = new BinaryFileService( rockContext );
PersonAliasService personAliasService = new PersonAliasService( rockContext );
PersonDuplicateService personDuplicateService = new PersonDuplicateService( rockContext );
NoteService noteService = new NoteService( rockContext );
AuthService authService = new AuthService( rockContext );
CommunicationService communicationService = new CommunicationService( rockContext );
CommunicationRecipientService communicationRecipientService = new CommunicationRecipientService( rockContext );
FinancialBatchService financialBatchService = new FinancialBatchService( rockContext );
FinancialTransactionService financialTransactionService = new FinancialTransactionService( rockContext );
PersonPreviousNameService personPreviousNameService = new PersonPreviousNameService( rockContext );
ConnectionRequestService connectionRequestService = new ConnectionRequestService( rockContext );
ConnectionRequestActivityService connectionRequestActivityService = new ConnectionRequestActivityService( rockContext );
// delete the batch data
List<int> imageIds = new List<int>();
foreach ( var batch in financialBatchService.Queryable().Where( b => b.Name.StartsWith( "SampleData" ) ) )
{
imageIds.AddRange( batch.Transactions.SelectMany( t => t.Images ).Select( i => i.BinaryFileId ).ToList() );
financialTransactionService.DeleteRange( batch.Transactions );
financialBatchService.Delete( batch );
}
// delete all transaction images
foreach ( var image in binaryFileService.GetByIds( imageIds ) )
{
binaryFileService.Delete( image );
}
foreach ( var elemFamily in families.Elements( "family" ) )
{
Guid guid = elemFamily.Attribute( "guid" ).Value.Trim().AsGuid();
GroupService groupService = new GroupService( rockContext );
Group family = groupService.Get( guid );
if ( family != null )
{
var groupMemberService = new GroupMemberService( rockContext );
var members = groupMemberService.GetByGroupId( family.Id, true );
// delete the people records
string errorMessage;
List<int> photoIds = members.Select( m => m.Person ).Where( p => p.PhotoId != null ).Select( a => (int)a.PhotoId ).ToList();
foreach ( var person in members.Select( m => m.Person ) )
{
person.GivingGroup = null;
person.GivingGroupId = null;
person.PhotoId = null;
// delete phone numbers
foreach ( var phone in phoneNumberService.GetByPersonId( person.Id ) )
{
if ( phone != null )
{
phoneNumberService.Delete( phone );
}
}
// delete communication recipient
foreach ( var recipient in communicationRecipientService.Queryable().Where( r => r.PersonAlias.PersonId == person.Id ) )
{
communicationRecipientService.Delete( recipient );
}
// delete communication
foreach ( var communication in communicationService.Queryable().Where( c => c.SenderPersonAliasId == person.PrimaryAlias.Id ) )
{
communicationService.Delete( communication );
}
// delete person viewed records
foreach ( var view in personViewedService.GetByTargetPersonId( person.Id ) )
{
personViewedService.Delete( view );
}
// delete page viewed records
foreach ( var view in pageViewService.GetByPersonId( person.Id ) )
{
pageViewService.Delete( view );
}
// delete notes created by them or on their record.
foreach ( var note in noteService.Queryable().Where ( n => n.CreatedByPersonAlias.PersonId == person.Id
|| (n.NoteType.EntityTypeId == _personEntityTypeId && n.EntityId == person.Id ) ) )
{
noteService.Delete( note );
//.........这里部分代码省略.........
示例5: lbUnfollow_Click
/// <summary>
/// Handles the Click event of the lbUnfollow control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
void lbUnfollow_Click( object sender, EventArgs e )
{
var itemsSelected = new List<int>();
gFollowings.SelectedKeys.ToList().ForEach( f => itemsSelected.Add( f.ToString().AsInteger() ) );
if ( itemsSelected.Any() )
{
var rockContext = new RockContext();
var personAliasService = new PersonAliasService( rockContext );
var followingService = new FollowingService( rockContext );
var paQry = personAliasService.Queryable()
.Where( p => itemsSelected.Contains( p.PersonId ) )
.Select( p => p.Id );
int personAliasEntityTypeId = EntityTypeCache.Read( "Rock.Model.PersonAlias" ).Id;
foreach ( var following in followingService.Queryable()
.Where( f =>
f.EntityTypeId == personAliasEntityTypeId &&
paQry.Contains( f.EntityId ) &&
f.PersonAliasId == CurrentPersonAlias.Id ) )
{
followingService.Delete( following );
}
rockContext.SaveChanges();
}
BindGrid();
}
示例6: GetPersonAliasFromActionAttribute
private Person GetPersonAliasFromActionAttribute(string key, RockContext rockContext, WorkflowAction action, List<string> errorMessages)
{
string value = GetAttributeValue( action, key );
Guid guidPersonAttribute = value.AsGuid();
if (!guidPersonAttribute.IsEmpty())
{
var attributePerson = AttributeCache.Read( guidPersonAttribute, rockContext );
if (attributePerson != null)
{
string attributePersonValue = action.GetWorklowAttributeValue(guidPersonAttribute);
if (!string.IsNullOrWhiteSpace(attributePersonValue))
{
if (attributePerson.FieldType.Class == "Rock.Field.Types.PersonFieldType")
{
Guid personAliasGuid = attributePersonValue.AsGuid();
if (!personAliasGuid.IsEmpty())
{
PersonAliasService personAliasService = new PersonAliasService(rockContext);
return personAliasService.Queryable().AsNoTracking()
.Where(a => a.Guid.Equals(personAliasGuid))
.Select(a => a.Person)
.FirstOrDefault();
}
else
{
errorMessages.Add(string.Format("Person could not be found for selected value ('{0}')!", guidPersonAttribute.ToString()));
return null;
}
}
else
{
errorMessages.Add(string.Format("The attribute used for {0} to provide the person was not of type 'Person'.", key));
return null;
}
}
}
}
return null;
}
示例7: GetSuggestions
/// <summary>
/// Gets the suggestions.
/// </summary>
/// <param name="followingSuggestionType">Type of the following suggestion.</param>
/// <param name="followerPersonIds">The follower person ids.</param>
/// <returns></returns>
public override List<PersonEntitySuggestion> GetSuggestions( FollowingSuggestionType followingSuggestionType, List<int> followerPersonIds )
{
var suggestions = new List<PersonEntitySuggestion>();
var personAliasEntityType = EntityTypeCache.Read( typeof( Rock.Model.PersonAlias ) );
bool isAutoFollow = GetAttributeValue( followingSuggestionType, "AutoFollow" ).AsBoolean();
// Get the grouptype guid
Guid? groupTypeGuid = GetAttributeValue( followingSuggestionType, "GroupType" ).AsGuidOrNull();
if ( groupTypeGuid.HasValue )
{
using ( var rockContext = new RockContext() )
{
var groupMemberService = new GroupMemberService( rockContext );
var personAliasService = new PersonAliasService( rockContext );
// Get all the groupmember records for any follower and the selected group type
var followers = groupMemberService.Queryable().AsNoTracking()
.Where( m =>
m.GroupMemberStatus == GroupMemberStatus.Active &&
m.Group != null &&
m.Group.IsActive &&
m.Group.GroupType.Guid.Equals( groupTypeGuid.Value ) &&
followerPersonIds.Contains( m.PersonId ) );
// If a specific group or security role was specifed, limit groupmembers to only those of the selected group
Guid? groupGuid = GetAttributeValue( followingSuggestionType, "Group" ).AsGuidOrNull();
if ( !groupGuid.HasValue )
{
groupGuid = GetAttributeValue( followingSuggestionType, "SecurityRole" ).AsGuidOrNull();
}
if ( groupGuid.HasValue )
{
followers = followers.Where( m => m.Group.Guid.Equals( groupGuid.Value ) );
}
// If a specific role for the follower was specified, limit groupmembers to only those with the selected role
Guid? followerRoleGuid = GetAttributeValue( followingSuggestionType, "FollowerGroupType" ).AsGuidOrNull();
if ( followerRoleGuid.HasValue )
{
followers = followers.Where( m => m.GroupRole.Guid.Equals( followerRoleGuid.Value ) );
}
// Run the query to get all the groups that follower is a member of with selected filters
var followerPersonGroup = followers
.Select( f => new
{
f.PersonId,
f.GroupId
} )
.ToList();
// Get a unique list of any of the groups that followers belong to
var followedGroupIds = followerPersonGroup
.Select( f => f.GroupId )
.Distinct()
.ToList();
// Start building query to get the people to follow from any group that contains a follower
var followed = groupMemberService
.Queryable().AsNoTracking()
.Where( m => followedGroupIds.Contains( m.GroupId ) );
// If a specific role for the people being followed was specified, limit the query to only those with the selected role
Guid? followedRoleGuid = GetAttributeValue( followingSuggestionType, "FollowedGroupType" ).AsGuidOrNull();
if ( followedRoleGuid.HasValue )
{
followed = followed.Where( m => m.GroupRole.Guid.Equals( followedRoleGuid.Value ) );
}
// Get all the people in any of the groups that contain a follower
var followedPersonGroup = followed
.Select( f => new
{
f.PersonId,
f.GroupId
} )
.ToList();
// Get distinct list of people
var followedPersonIds = followedPersonGroup
.Select( f => f.PersonId )
.Distinct()
.ToList();
// Build a dictionary of the personid->personaliasid
var personAliasIds = new Dictionary<int, int>();
personAliasService.Queryable().AsNoTracking()
.Where( a =>
followedPersonIds.Contains( a.PersonId ) &&
a.PersonId == a.AliasPersonId )
.ToList()
.ForEach( a => personAliasIds.AddOrIgnore( a.PersonId, a.Id ) );
//.........这里部分代码省略.........
示例8: DeleteExistingFamilyData
/// <summary>
/// Deletes the family's addresses, phone numbers, photos, viewed records, and people.
/// TODO: delete attendance codes for attendance data that's about to be deleted when
/// we delete the person record.
/// </summary>
/// <param name="families">The families.</param>
/// <param name="rockContext">The rock context.</param>
private void DeleteExistingFamilyData( XElement families, RockContext rockContext )
{
PersonService personService = new PersonService( rockContext );
PhoneNumberService phoneNumberService = new PhoneNumberService( rockContext );
PersonViewedService personViewedService = new PersonViewedService( rockContext );
PageViewService pageViewService = new PageViewService( rockContext );
BinaryFileService binaryFileService = new BinaryFileService( rockContext );
PersonAliasService personAliasService = new PersonAliasService( rockContext );
NoteService noteService = new NoteService( rockContext );
AuthService authService = new AuthService( rockContext );
foreach ( var elemFamily in families.Elements( "family" ) )
{
Guid guid = elemFamily.Attribute( "guid" ).Value.Trim().AsGuid();
GroupService groupService = new GroupService( rockContext );
Group family = groupService.Get( guid );
if ( family != null )
{
var groupMemberService = new GroupMemberService( rockContext );
var members = groupMemberService.GetByGroupId( family.Id );
// delete the people records
string errorMessage;
List<int> photoIds = members.Select( m => m.Person ).Where( p => p.PhotoId != null ).Select( a => (int)a.PhotoId ).ToList();
foreach ( var person in members.Select( m => m.Person ) )
{
person.GivingGroup = null;
person.GivingGroupId = null;
person.PhotoId = null;
// delete phone numbers
foreach ( var phone in phoneNumberService.GetByPersonId( person.Id ) )
{
if ( phone != null )
{
phoneNumberService.Delete( phone );
}
}
// delete person viewed records
foreach ( var view in personViewedService.GetByTargetPersonId( person.Id ) )
{
personViewedService.Delete( view );
}
// delete page viewed records
foreach ( var view in pageViewService.GetByPersonId( person.Id ) )
{
pageViewService.Delete( view );
}
// delete notes created by them or on their record.
foreach ( var note in noteService.Queryable().Where ( n => n.CreatedByPersonAlias.PersonId == person.Id
|| (n.NoteType.EntityTypeId == _personEntityTypeId && n.EntityId == person.Id ) ) )
{
noteService.Delete( note );
}
//// delete any GroupMember records they have
//foreach ( var groupMember in groupMemberService.Queryable().Where( gm => gm.PersonId == person.Id ) )
//{
// groupMemberService.Delete( groupMember );
//}
//// delete any Authorization data
//foreach ( var auth in authService.Queryable().Where( a => a.PersonId == person.Id ) )
//{
// authService.Delete( auth );
//}
// delete their aliases
foreach ( var alias in personAliasService.Queryable().Where( a => a.PersonId == person.Id ) )
{
personAliasService.Delete( alias );
}
//foreach ( var relationship in person.Gro)
// Save these changes so the CanDelete passes the check...
//rockContext.ChangeTracker.DetectChanges();
rockContext.SaveChanges( disablePrePostProcessing: true );
if ( personService.CanDelete( person, out errorMessage ) )
{
personService.Delete( person );
//rockContext.ChangeTracker.DetectChanges();
//rockContext.SaveChanges( disablePrePostProcessing: true );
}
}
//rockContext.ChangeTracker.DetectChanges();
rockContext.SaveChanges( disablePrePostProcessing: true );
//.........这里部分代码省略.........
示例9: SetFollowing
private void SetFollowing()
{
var personAliasEntityType = EntityTypeCache.Read( "Rock.Model.PersonAlias" );
if ( Person != null && CurrentPersonId.HasValue && CurrentPersonAlias != null && personAliasEntityType != null )
{
using ( var rockContext = new RockContext() )
{
var personAliasService = new PersonAliasService( rockContext );
var followingService = new FollowingService( rockContext );
var paQry = personAliasService.Queryable()
.Where( p => p.PersonId == Person.Id )
.Select( p => p.Id );
if ( followingService.Queryable()
.Where( f =>
f.EntityTypeId == personAliasEntityType.Id &&
paQry.Contains( f.EntityId ) &&
f.PersonAlias.PersonId == CurrentPersonId )
.Any() )
{
pnlFollow.AddCssClass( "following" );
}
else
{
pnlFollow.RemoveCssClass( "following" );
}
}
string script = string.Format( @"
$('.following-status').click(function () {{
var $followingDiv = $(this);
if ($followingDiv.hasClass('following')) {{
$.ajax({{
type: 'DELETE',
url: Rock.settings.get('baseUrl') + 'api/followings/{0}/{1}/{2}',
success: function(data, status, xhr){{
$followingDiv.removeClass('following');
}},
}});
}} else {{
var following = {{ EntityTypeId:{0}, EntityId:{1}, PersonAliasId:{3} }};
$.ajax({{
type: 'POST',
contentType: 'application/json',
data: JSON.stringify(following),
url: Rock.settings.get('baseUrl') + 'api/followings',
statusCode: {{
201: function () {{
$followingDiv.addClass('following');
}}
}}
}});
}}
}});
", personAliasEntityType.Id, Person.PrimaryAliasId, CurrentPersonId.Value, CurrentPersonAlias.Id );
ScriptManager.RegisterStartupScript( lImage, lImage.GetType(), "following", script, true );
}
}
示例10: PersonCleanup
/// <summary>
/// Does cleanup of Person Aliases and Metaphones
/// </summary>
/// <param name="dataMap">The data map.</param>
private void PersonCleanup( JobDataMap dataMap )
{
// Add any missing person aliases
var personRockContext = new Rock.Data.RockContext();
PersonService personService = new PersonService( personRockContext );
PersonAliasService personAliasService = new PersonAliasService( personRockContext );
var personAliasServiceQry = personAliasService.Queryable();
foreach ( var person in personService.Queryable( "Aliases" )
.Where( p => !p.Aliases.Any() && !personAliasServiceQry.Any( pa => pa.AliasPersonId == p.Id ) )
.Take( 300 ) )
{
person.Aliases.Add( new PersonAlias { AliasPersonId = person.Id, AliasPersonGuid = person.Guid } );
}
personRockContext.SaveChanges();
// Add any missing metaphones
int namesToProcess = dataMap.GetString( "MaxMetaphoneNames" ).AsInteger();
if ( namesToProcess > 0 )
{
var firstNameQry = personService.Queryable().Select( p => p.FirstName ).Where( p => p != null );
var nickNameQry = personService.Queryable().Select( p => p.NickName ).Where( p => p != null );
var lastNameQry = personService.Queryable().Select( p => p.LastName ).Where( p => p != null );
var nameQry = firstNameQry.Union( nickNameQry.Union( lastNameQry ) );
var metaphones = personRockContext.Metaphones;
var existingNames = metaphones.Select( m => m.Name ).Distinct();
// Get the names that have not yet been processed
var namesToUpdate = nameQry
.Where( n => !existingNames.Contains( n ) )
.Take( namesToProcess )
.ToList();
foreach ( string name in namesToUpdate )
{
string mp1 = string.Empty;
string mp2 = string.Empty;
Rock.Utility.DoubleMetaphone.doubleMetaphone( name, ref mp1, ref mp2 );
var metaphone = new Metaphone();
metaphone.Name = name;
metaphone.Metaphone1 = mp1;
metaphone.Metaphone2 = mp2;
metaphones.Add( metaphone );
}
personRockContext.SaveChanges();
}
}
示例11: MapGroups
//Just mapping Connect Groups and not People Lists (Wonder if People lists could be Tags?)
/// <summary>
/// Maps the Connect Groups.
/// </summary>
/// <param name="tableData">The table data.</param>
/// <returns></returns>
private void MapGroups( IQueryable<Row> tableData )
{
var lookupContext = new RockContext();
int completedMembers = 0;
int completedGroups = 0;
int completedLifeStages = 0;
int completedTags = 0;
int completedIndividualTags = 0;
int totalRows = tableData.Count();
int percentage = ( totalRows - 1 ) / 100 + 1;
ReportProgress( 0, string.Format( "Verifying group import ({0:N0} found. Total may vary based on Group Type Name).", totalRows ) );
foreach ( var row in tableData )
{
var rockContext = new RockContext();
var lifeStageContext = new RockContext();
var connectGroupContext = new RockContext();
var connectGroupMemberContext = new RockContext();
string groupTypeName = row["Group_Type_Name"] as string;
if ( groupTypeName.Trim() == "Connect Groups" ) //Moves Connect Groups into Rock Groups
{
var groupTypeIdSection = new GroupTypeService( lookupContext ).Queryable().Where( gt => gt.Name == "Event/Serving/Small Group Section" ).Select( a => a.Id ).FirstOrDefault();
var connectGroupsId = new GroupService( lookupContext ).Queryable().Where( g => g.Name == "Connect Groups" && g.GroupTypeId == groupTypeIdSection ).Select( a => a.Id ).FirstOrDefault();
var groupTypeIdSmallGroup = new GroupTypeService( lookupContext ).Queryable().Where( gt => gt.Name == "Small Group" ).Select( a => a.Id ).FirstOrDefault();
string groupName = row["Group_Name"] as string;
int? groupId = row["Group_ID"] as int?;
int? individualId = row["Individual_ID"] as int?;
int? personId = GetPersonAliasId( individualId );
DateTime? createdDateTime = row["Created_Date"] as DateTime?;
//Check to see if Head of Connect Group Tree exists
//If it doesn't exist
if ( connectGroupsId == 0 )
{
//Create one.
var connectGroupTree = new Group();
connectGroupTree.IsSystem = false;
connectGroupTree.GroupTypeId = groupTypeIdSection;
connectGroupTree.CampusId = 1;
connectGroupTree.Name = "Connect Groups";
connectGroupTree.Description = "Crossroads Connect Group Ministry";
connectGroupTree.IsActive = true;
//connectGroupTree.Order = 0;
connectGroupTree.CreatedByPersonAliasId = 1;
connectGroupTree.CreatedDateTime = DateTime.Now;
//save group
rockContext.WrapTransaction( () =>
{
rockContext.Configuration.AutoDetectChangesEnabled = false;
rockContext.Groups.Add( connectGroupTree );
rockContext.SaveChanges( DisableAudit );
} );
}
//check to see if life stage exists
//getting the life stage name
string lifeStage = groupName;
int index = lifeStage.IndexOf( "-" );
if ( index > 0 )
lifeStage = lifeStage.Substring( 0, index ).Trim();
//checks to see if it exists
int existingLifeStage = new GroupService( lookupContext ).Queryable().Where( g => g.Name == lifeStage ).Select( a => a.Id ).FirstOrDefault();
if ( existingLifeStage == 0 )
{
//Create one.
var connectGroupsLifeStage = new Group();
connectGroupsLifeStage.IsSystem = false;
connectGroupsLifeStage.ParentGroupId = connectGroupsId;
connectGroupsLifeStage.GroupTypeId = groupTypeIdSection;
connectGroupsLifeStage.CampusId = 1;
connectGroupsLifeStage.Name = lifeStage;
connectGroupsLifeStage.Description = "";
connectGroupsLifeStage.IsActive = true;
//connectGroupsLifeStage.Order = 0;
connectGroupsLifeStage.CreatedByPersonAliasId = 1;
connectGroupsLifeStage.CreatedDateTime = DateTime.Now;
//save Life Stage
lifeStageContext.WrapTransaction( () =>
{
lifeStageContext.Configuration.AutoDetectChangesEnabled = false;
lifeStageContext.Groups.Add( connectGroupsLifeStage );
lifeStageContext.SaveChanges( DisableAudit );
} );
completedLifeStages++;
}
//.........这里部分代码省略.........
示例12: GetEditValue
/// <summary>
/// Reads new values entered by the user for the field (as PersonAlias.Guid)
/// </summary>
/// <param name="control">Parent control that controls were added to in the CreateEditControl() method</param>
/// <param name="configurationValues">The configuration values.</param>
/// <returns></returns>
public override string GetEditValue( System.Web.UI.Control control, Dictionary<string, ConfigurationValue> configurationValues )
{
PersonPicker ppPerson = control as PersonPicker;
string result = null;
if ( ppPerson != null )
{
Guid personGuid = Guid.Empty;
int? personId = ppPerson.PersonId;
if ( personId.HasValue )
{
var rockContext = new RockContext();
var personAliasService = new PersonAliasService( rockContext );
var personAlias = personAliasService.Queryable()
.Where( a => a.AliasPersonId == personId )
.FirstOrDefault();
if ( personAlias != null )
{
result = personAlias.Guid.ToString();
}
else
{
// If the personId is valid, there should be a personAlias with the AliasPersonID equal
// to that personId. If there isn't for some reason, create it now...
var person = new PersonService( rockContext ).Get( personId.Value );
if ( person != null )
{
personAlias = new PersonAlias();
personAlias.Guid = Guid.NewGuid();
personAlias.AliasPersonId = person.Id;
personAlias.AliasPersonGuid = person.Guid;
personAlias.PersonId = person.Id;
result = personAlias.Guid.ToString();
personAliasService.Add( personAlias );
rockContext.SaveChanges();
}
}
}
}
return result;
}