本文整理汇总了C#中Rock.Model.GroupTypeRoleService.Get方法的典型用法代码示例。如果您正苦于以下问题:C# GroupTypeRoleService.Get方法的具体用法?C# GroupTypeRoleService.Get怎么用?C# GroupTypeRoleService.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rock.Model.GroupTypeRoleService
的用法示例。
在下文中一共展示了GroupTypeRoleService.Get方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetInverseRole
protected GroupTypeRole GetInverseRole( GroupTypeRole role, GroupTypeRoleService groupRoleServ )
{
role.LoadAttributes();
return groupRoleServ.Get( role.GetAttributeValue( "InverseRelationship" ).AsGuid() );
}
示例2: SaveIndividuals
/// <summary>
/// Saves the individuals.
/// </summary>
/// <param name="newFamilyList">The family list.</param>
/// <param name="visitorList">The optional visitor list.</param>
private void SaveIndividuals( List<Group> newFamilyList, List<Group> visitorList = null, List<Note> newNoteList = null )
{
if ( newFamilyList.Any() )
{
var rockContext = new RockContext();
rockContext.WrapTransaction( ( ) =>
{
rockContext.Groups.AddRange( newFamilyList );
rockContext.SaveChanges( DisableAuditing );
ImportedFamilies.AddRange( newFamilyList );
foreach ( var familyGroups in newFamilyList.GroupBy<Group, string>( g => g.ForeignKey ) )
{
bool visitorsExist = visitorList.Any() && familyGroups.Any();
foreach ( var newFamilyGroup in familyGroups )
{
foreach ( var person in newFamilyGroup.Members.Select( m => m.Person ) )
{
// Set notes on this person
if ( newNoteList.Any( n => n.ForeignKey == person.ForeignKey ) )
{
newNoteList.Where( n => n.ForeignKey == person.ForeignKey ).ToList()
.ForEach( n => n.EntityId = person.Id );
}
// Set attributes on this person
foreach ( var attributeCache in person.Attributes.Select( a => a.Value ) )
{
var existingValue = rockContext.AttributeValues.FirstOrDefault( v => v.Attribute.Key == attributeCache.Key && v.EntityId == person.Id );
var newAttributeValue = person.AttributeValues[attributeCache.Key];
// set the new value and add it to the database
if ( existingValue == null )
{
existingValue = new AttributeValue();
existingValue.AttributeId = newAttributeValue.AttributeId;
existingValue.EntityId = person.Id;
existingValue.Value = newAttributeValue.Value;
rockContext.AttributeValues.Add( existingValue );
}
else
{
existingValue.Value = newAttributeValue.Value;
rockContext.Entry( existingValue ).State = EntityState.Modified;
}
}
// Set aliases on this person
if ( !person.Aliases.Any( a => a.PersonId == person.Id ) )
{
person.Aliases.Add( new PersonAlias
{
AliasPersonId = person.Id,
AliasPersonGuid = person.Guid,
ForeignKey = person.ForeignKey,
ForeignId = person.ForeignId,
PersonId = person.Id
} );
}
person.GivingGroupId = newFamilyGroup.Id;
if ( visitorsExist )
{
var groupTypeRoleService = new GroupTypeRoleService( rockContext );
var ownerRole = groupTypeRoleService.Get( new Guid( Rock.SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_OWNER ) );
int inviteeRoleId = groupTypeRoleService.Get( new Guid( Rock.SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_INVITED ) ).Id;
int invitedByRoleId = groupTypeRoleService.Get( new Guid( Rock.SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_INVITED_BY ) ).Id;
int canCheckInRoleId = groupTypeRoleService.Get( new Guid( Rock.SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_CAN_CHECK_IN ) ).Id;
int allowCheckInByRoleId = groupTypeRoleService.Get( new Guid( Rock.SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_ALLOW_CHECK_IN_BY ) ).Id;
// Retrieve or create the group this person is an owner of
var ownerGroup = new GroupMemberService( rockContext ).Queryable()
.Where( m => m.PersonId == person.Id && m.GroupRoleId == ownerRole.Id )
.Select( m => m.Group ).FirstOrDefault();
if ( ownerGroup == null )
{
var ownerGroupMember = new GroupMember();
ownerGroupMember.PersonId = person.Id;
ownerGroupMember.GroupRoleId = ownerRole.Id;
ownerGroup = new Group();
ownerGroup.Name = ownerRole.GroupType.Name;
ownerGroup.GroupTypeId = ownerRole.GroupTypeId.Value;
ownerGroup.Members.Add( ownerGroupMember );
rockContext.Groups.Add( ownerGroup );
}
// Visitor, add relationships to the family members
if ( visitorList.Where( v => v.ForeignKey == newFamilyGroup.ForeignKey )
.Any( v => v.Members.Any( m => m.Person.ForeignKey.Equals( person.ForeignKey ) ) ) )
{
var familyMembers = familyGroups.Except( visitorList ).SelectMany( g => g.Members );
//.........这里部分代码省略.........
示例3: LoadIndividuals
/// <summary>
/// Loads the individual data.
/// </summary>
/// <param name="csvData">The CSV data.</param>
private int LoadIndividuals( CSVInstance csvData )
{
var lookupContext = new RockContext();
var groupTypeRoleService = new GroupTypeRoleService( lookupContext );
var groupMemberService = new GroupMemberService( lookupContext );
// Marital statuses: Married, Single, Separated, etc
var maritalStatusTypes = DefinedTypeCache.Read( new Guid( Rock.SystemGuid.DefinedType.PERSON_MARITAL_STATUS ), lookupContext ).DefinedValues;
// Connection statuses: Member, Visitor, Attendee, etc
var connectionStatusTypes = DefinedTypeCache.Read( new Guid( Rock.SystemGuid.DefinedType.PERSON_CONNECTION_STATUS ), lookupContext ).DefinedValues;
int memberConnectionStatusId = connectionStatusTypes.FirstOrDefault( dv => dv.Guid == new Guid( Rock.SystemGuid.DefinedValue.PERSON_CONNECTION_STATUS_MEMBER ) ).Id;
int visitorConnectionStatusId = connectionStatusTypes.FirstOrDefault( dv => dv.Guid == new Guid( Rock.SystemGuid.DefinedValue.PERSON_CONNECTION_STATUS_VISITOR ) ).Id;
int attendeeConnectionStatusId = connectionStatusTypes.FirstOrDefault( dv => dv.Guid == new Guid( Rock.SystemGuid.DefinedValue.PERSON_CONNECTION_STATUS_ATTENDEE ) ).Id;
// Suffix type: Dr., Jr., II, etc
var suffixTypes = DefinedTypeCache.Read( new Guid( Rock.SystemGuid.DefinedType.PERSON_SUFFIX ), lookupContext ).DefinedValues;
// Title type: Mr., Mrs. Dr., etc
var titleTypes = DefinedTypeCache.Read( new Guid( Rock.SystemGuid.DefinedType.PERSON_TITLE ), lookupContext ).DefinedValues;
// Record statuses: Active, Inactive, Pending
int? recordStatusActiveId = DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.PERSON_RECORD_STATUS_ACTIVE ), lookupContext ).Id;
int? recordStatusInactiveId = DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.PERSON_RECORD_STATUS_INACTIVE ), lookupContext ).Id;
int? recordStatusPendingId = DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.PERSON_RECORD_STATUS_PENDING ), lookupContext ).Id;
// Deceased record status reason (others available: No Activity, Moved, etc)
var recordStatusDeceasedId = DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.PERSON_RECORD_STATUS_REASON_DECEASED ) ).Id;
// Record type: Person
int? personRecordTypeId = DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.PERSON_RECORD_TYPE_PERSON ), lookupContext ).Id;
// Group roles: Owner, Adult, Child, others
GroupTypeRole ownerRole = groupTypeRoleService.Get( new Guid( Rock.SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_OWNER ) );
int adultRoleId = groupTypeRoleService.Get( new Guid( Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_ADULT ) ).Id;
int childRoleId = groupTypeRoleService.Get( new Guid( Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_CHILD ) ).Id;
// Phone types: Home, Work, Mobile
var numberTypeValues = DefinedTypeCache.Read( new Guid( Rock.SystemGuid.DefinedType.PERSON_PHONE_TYPE ), lookupContext ).DefinedValues;
// Personal note type id
var personalNoteTypeId = new NoteTypeService( lookupContext ).Get( new Guid( Rock.SystemGuid.NoteType.PERSON_TIMELINE_NOTE ) ).Id;
// School defined type
var schoolDefinedType = DefinedTypeCache.Read( new Guid( "576FF1E2-6225-4565-A16D-230E26167A3D" ) );
// Look up existing Person attributes
var personAttributes = new AttributeService( lookupContext ).GetByEntityTypeId( PersonEntityTypeId ).ToList();
var schoolAttribute = AttributeCache.Read( personAttributes.FirstOrDefault( a => a.Key == "School" ) );
// Text field type id
int textFieldTypeId = FieldTypeCache.Read( new Guid( Rock.SystemGuid.FieldType.TEXT ), lookupContext ).Id;
int dateFieldTypeId = FieldTypeCache.Read( new Guid( Rock.SystemGuid.FieldType.DATE ), lookupContext ).Id;
// Attribute entity type id
int attributeEntityTypeId = EntityTypeCache.Read( "Rock.Model.Attribute" ).Id;
// Visit info category
var visitInfoCategory = new CategoryService( lookupContext ).GetByEntityTypeId( attributeEntityTypeId )
.Where( c => c.Name == "Visit Information" ).FirstOrDefault();
// Look for custom attributes in the Individual file
var allFields = csvData.TableNodes.FirstOrDefault().Children.Select( ( node, index ) => new { node = node, index = index } ).ToList();
Dictionary<int, string> customAttributes = allFields
.Where( f => f.index > SecurityNote )
.ToDictionary( f => f.index, f => f.node.Name.RemoveWhitespace() );
// Add any attributes if they don't already exist
if ( customAttributes.Any() )
{
var newAttributes = new List<Rock.Model.Attribute>();
foreach ( var newAttributePair in customAttributes.Where( ca => !personAttributes.Any( a => a.Key == ca.Value ) ) )
{
var newAttribute = new Rock.Model.Attribute();
newAttribute.Name = newAttributePair.Value;
newAttribute.Key = newAttributePair.Value.RemoveWhitespace();
newAttribute.Description = newAttributePair.Value + " created by CSV import";
newAttribute.EntityTypeQualifierValue = string.Empty;
newAttribute.EntityTypeQualifierColumn = string.Empty;
newAttribute.EntityTypeId = PersonEntityTypeId;
newAttribute.FieldTypeId = textFieldTypeId;
newAttribute.DefaultValue = string.Empty;
newAttribute.IsMultiValue = false;
newAttribute.IsGridColumn = false;
newAttribute.IsRequired = false;
newAttribute.Order = 0;
newAttributes.Add( newAttribute );
}
lookupContext.Attributes.AddRange( newAttributes );
lookupContext.SaveChanges( DisableAuditing );
personAttributes.AddRange( newAttributes );
}
// Set the supported date formats
var dateFormats = new[] { "yyyy-MM-dd", "MM/dd/yyyy", "MM/dd/yy" };
//.........这里部分代码省略.........
示例4: MapPerson
/// <summary>
/// Maps the person.
/// </summary>
/// <param name="tableData">The table data.</param>
/// <param name="selectedColumns">The selected columns.</param>
public void MapPerson( IQueryable<Row> tableData )
{
var lookupContext = new RockContext();
var groupTypeRoleService = new GroupTypeRoleService( lookupContext );
// Marital statuses: Married, Single, Separated, etc
var maritalStatusTypes = DefinedTypeCache.Read( new Guid( Rock.SystemGuid.DefinedType.PERSON_MARITAL_STATUS ), lookupContext ).DefinedValues;
// Connection statuses: Member, Visitor, Attendee, etc
var connectionStatusTypes = DefinedTypeCache.Read( new Guid( Rock.SystemGuid.DefinedType.PERSON_CONNECTION_STATUS ), lookupContext ).DefinedValues;
int memberStatusId = connectionStatusTypes.FirstOrDefault( dv => dv.Guid == new Guid( Rock.SystemGuid.DefinedValue.PERSON_CONNECTION_STATUS_MEMBER ) ).Id;
int visitorStatusId = connectionStatusTypes.FirstOrDefault( dv => dv.Guid == new Guid( Rock.SystemGuid.DefinedValue.PERSON_CONNECTION_STATUS_VISITOR ) ).Id;
int attendeeStatusId = connectionStatusTypes.FirstOrDefault( dv => dv.Guid == new Guid( Rock.SystemGuid.DefinedValue.PERSON_CONNECTION_STATUS_ATTENDEE ) ).Id;
// Record statuses/reasons: Active, Inactive, Pending, Deceased, etc
var recordStatuses = DefinedTypeCache.Read( new Guid( Rock.SystemGuid.DefinedType.PERSON_RECORD_STATUS ) ).DefinedValues;
var recordStatusReasons = DefinedTypeCache.Read( new Guid( Rock.SystemGuid.DefinedType.PERSON_RECORD_STATUS_REASON ), lookupContext ).DefinedValues;
int recordStatusActiveId = recordStatuses.FirstOrDefault( r => r.Guid == new Guid( Rock.SystemGuid.DefinedValue.PERSON_RECORD_STATUS_ACTIVE ) ).Id;
int recordStatusInactiveId = recordStatuses.FirstOrDefault( r => r.Guid == new Guid( Rock.SystemGuid.DefinedValue.PERSON_RECORD_STATUS_INACTIVE ) ).Id;
int recordStatusPendingId = recordStatuses.FirstOrDefault( r => r.Guid == new Guid( Rock.SystemGuid.DefinedValue.PERSON_RECORD_STATUS_PENDING ) ).Id;
int statusReasonDeceasedId = recordStatusReasons.FirstOrDefault( dv => dv.Guid == new Guid( Rock.SystemGuid.DefinedValue.PERSON_RECORD_STATUS_REASON_DECEASED ) ).Id;
int statusReasonNoActivityId = recordStatusReasons.Where( dv => dv.Value == "No Activity" ).Select( dv => dv.Id ).FirstOrDefault();
// Record type: Person
int? personRecordTypeId = DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.PERSON_RECORD_TYPE_PERSON ), lookupContext ).Id;
// Suffix type: Dr., Jr., II, etc
var suffixTypes = DefinedTypeCache.Read( new Guid( Rock.SystemGuid.DefinedType.PERSON_SUFFIX ) ).DefinedValues;
// Title type: Mr., Mrs. Dr., etc
var titleTypes = DefinedTypeCache.Read( new Guid( Rock.SystemGuid.DefinedType.PERSON_TITLE ), lookupContext ).DefinedValues;
// Group roles: Owner, Adult, Child, others
GroupTypeRole ownerRole = groupTypeRoleService.Get( new Guid( Rock.SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_OWNER ) );
int adultRoleId = groupTypeRoleService.Get( new Guid( Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_ADULT ) ).Id;
int childRoleId = groupTypeRoleService.Get( new Guid( Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_CHILD ) ).Id;
int inviteeRoleId = groupTypeRoleService.Get( new Guid( Rock.SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_INVITED ) ).Id;
int invitedByRoleId = groupTypeRoleService.Get( new Guid( Rock.SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_INVITED_BY ) ).Id;
int canCheckInRoleId = groupTypeRoleService.Get( new Guid( Rock.SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_CAN_CHECK_IN ) ).Id;
int allowCheckInByRoleId = groupTypeRoleService.Get( new Guid( Rock.SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_ALLOW_CHECK_IN_BY ) ).Id;
// Group type: Family
int familyGroupTypeId = new GroupTypeService( lookupContext ).Get( new Guid( Rock.SystemGuid.GroupType.GROUPTYPE_FAMILY ) ).Id;
// Look up additional Person attributes (existing)
var personAttributes = new AttributeService( lookupContext ).GetByEntityTypeId( PersonEntityTypeId ).AsNoTracking().ToList();
// F1 attributes: IndividualId, HouseholdId
// Core attributes: PreviousChurch, Position, Employer, School
var previousChurchAttribute = AttributeCache.Read( personAttributes.FirstOrDefault( a => a.Key.Equals( "PreviousChurch", StringComparison.InvariantCultureIgnoreCase ) ) );
var membershipDateAttribute = AttributeCache.Read( personAttributes.FirstOrDefault( a => a.Key.Equals( "MembershipDate", StringComparison.InvariantCultureIgnoreCase ) ) );
var firstVisitAttribute = AttributeCache.Read( personAttributes.FirstOrDefault( a => a.Key.Equals( "FirstVisit", StringComparison.InvariantCultureIgnoreCase ) ) );
var legalNoteAttribute = AttributeCache.Read( personAttributes.FirstOrDefault( a => a.Key.Equals( "LegalNotes", StringComparison.InvariantCultureIgnoreCase ) ) );
var employerAttribute = AttributeCache.Read( personAttributes.FirstOrDefault( a => a.Key.Equals( "Employer", StringComparison.InvariantCultureIgnoreCase ) ) );
var positionAttribute = AttributeCache.Read( personAttributes.FirstOrDefault( a => a.Key.Equals( "Position", StringComparison.InvariantCultureIgnoreCase ) ) );
var schoolAttribute = AttributeCache.Read( personAttributes.FirstOrDefault( a => a.Key.Equals( "School", StringComparison.InvariantCultureIgnoreCase ) ) );
var familyList = new List<Group>();
var visitorList = new List<Group>();
var previousNamesList = new Dictionary<Guid, string>();
var householdCampusList = new List<string>();
int completed = 0;
int totalRows = tableData.Count();
int percentage = ( totalRows - 1 ) / 100 + 1;
ReportProgress( 0, string.Format( "Verifying person import ({0:N0} found, {1:N0} already exist).", totalRows, ImportedPeople.Count ) );
foreach ( var groupedRows in tableData.GroupBy<Row, int?>( r => r["Household_ID"] as int? ) )
{
var familyGroup = new Group();
householdCampusList.Clear();
foreach ( var row in groupedRows.Where( r => r != null ) )
{
var familyRoleId = FamilyRole.Adult;
string currentCampus = string.Empty;
int? individualId = row["Individual_ID"] as int?;
int? householdId = row["Household_ID"] as int?;
var personKeys = GetPersonKeys( individualId, householdId );
if ( personKeys == null )
{
var person = new Person();
person.FirstName = row["First_Name"] as string;
person.MiddleName = row["Middle_Name"] as string;
person.NickName = row["Goes_By"] as string ?? person.FirstName;
person.LastName = row["Last_Name"] as string;
person.IsDeceased = false;
var DOB = row["Date_Of_Birth"] as DateTime?;
if ( DOB != null )
{
var birthDate = (DateTime)DOB;
person.BirthDay = birthDate.Day;
person.BirthMonth = birthDate.Month;
//.........这里部分代码省略.........
示例5: ShowModal
private void ShowModal( Person person, int? roleId, int? groupMemberId )
{
Guid roleGuid = Guid.Empty;
if ( Guid.TryParse( GetAttributeValue( "GroupType/RoleFilter" ), out roleGuid ) )
{
var groupTypeRoleService = new GroupTypeRoleService( new RockContext() );
var role = groupTypeRoleService.Get( ownerRoleGuid );
grpRole.ExcludeGroupRoles.Add( role.Id );
grpRole.GroupTypeId = groupTypeRoleService.Queryable()
.Where( r => r.Guid == roleGuid )
.Select( r => r.GroupTypeId )
.FirstOrDefault();
}
grpRole.GroupRoleId = roleId;
ppPerson.SetValue( person );
ShowDialog( groupMemberId ?? 0, true );
}
示例6: MapCompany
/// <summary>
/// Maps the company.
/// </summary>
/// <param name="tableData">The table data.</param>
/// <returns></returns>
private void MapCompany( IQueryable<Row> tableData )
{
var groupTypeRoleService = new GroupTypeRoleService();
//var attributeValueService = new AttributeValueService();
var attributeService = new AttributeService();
//var personService = new PersonService();
//var groupService = new GroupService();
var businessList = new List<Group>();
// Record status: Active, Inactive, Pending
int? statusActiveId = DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.PERSON_RECORD_STATUS_ACTIVE ) ).Id;
int? statusInactiveId = DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.PERSON_RECORD_STATUS_INACTIVE ) ).Id;
int? statusPendingId = DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.PERSON_RECORD_STATUS_PENDING ) ).Id;
// Record type: Business
int? businessRecordTypeId = DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.PERSON_RECORD_TYPE_BUSINESS ) ).Id;
// Group role: TBD
int groupRoleId = groupTypeRoleService.Get( new Guid( Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_ADULT ) ).Id;
// Group type: Family
int familyGroupTypeId = GroupTypeCache.GetFamilyGroupType().Id;
// Cached F1 attribute: HouseholdId
var householdIdAttribute = AttributeCache.Read( HouseholdAttributeId );
int completed = 0;
int totalRows = tableData.Count();
int percentage = ( totalRows - 1 ) / 100 + 1;
ReportProgress( 0, string.Format( "Checking company import ({0:N0} found).", totalRows ) );
foreach ( var row in tableData )
{
int? householdId = row["Household_ID"] as int?;
if ( GetPersonId( null, householdId ) == null )
{
var businessGroup = new Group();
var business = new Person();
var businessName = row["Household_Name"] as string;
if ( businessName != null )
{
businessName.Replace( "'", "'" );
businessName.Replace( "&", "&" );
business.LastName = businessName.Left( 50 );
businessGroup.Name = businessName.Left( 50 );
}
business.CreatedByPersonAliasId = ImportPersonAlias.Id;
business.CreatedDateTime = row["Created_Date"] as DateTime?;
business.RecordTypeValueId = businessRecordTypeId;
business.Attributes = new Dictionary<string, AttributeCache>();
business.AttributeValues = new Dictionary<string, List<AttributeValue>>();
business.Attributes.Add( "F1HouseholdId", householdIdAttribute );
business.AttributeValues.Add( "F1HouseholdId", new List<AttributeValue>() );
business.AttributeValues["F1HouseholdId"].Add( new AttributeValue()
{
AttributeId = householdIdAttribute.Id,
Value = householdId.ToString(),
Order = 0
} );
var groupMember = new GroupMember();
groupMember.Person = business;
groupMember.GroupRoleId = groupRoleId;
groupMember.GroupMemberStatus = GroupMemberStatus.Active;
businessGroup.Members.Add( groupMember );
businessGroup.GroupTypeId = familyGroupTypeId;
businessList.Add( businessGroup );
completed++;
if ( completed % percentage < 1 )
{
int percentComplete = completed / percentage;
ReportProgress( percentComplete, string.Format( "{0:N0} companies imported ({1}% complete).", completed, percentComplete ) );
}
else if ( completed % ReportingNumber < 1 )
{
RockTransactionScope.WrapTransaction( () =>
{
var groupService = new GroupService();
var personService = new PersonService();
var attributeValueService = new AttributeValueService();
groupService.RockContext.Groups.AddRange( businessList );
groupService.RockContext.SaveChanges();
foreach ( var newBusiness in businessList )
{
foreach ( var businessMember in newBusiness.Members )
{
var person = businessMember.Person;
foreach ( var attributeCache in person.Attributes.Select( a => a.Value ) )
{
//.........这里部分代码省略.........
示例7: MapPerson
/// <summary>
/// Maps the person.
/// </summary>
/// <param name="tableData">The table data.</param>
/// <param name="selectedColumns">The selected columns.</param>
private void MapPerson( IQueryable<Row> tableData, List<string> selectedColumns = null )
{
var groupTypeRoleService = new GroupTypeRoleService();
var attributeService = new AttributeService();
var dvService = new DefinedValueService();
var familyList = new List<Group>();
// Marital statuses: Married, Single, Separated, etc
List<DefinedValue> maritalStatusTypes = dvService.Queryable()
.Where( dv => dv.DefinedType.Guid == new Guid( Rock.SystemGuid.DefinedType.PERSON_MARITAL_STATUS ) ).ToList();
// Connection statuses: Member, Visitor, Attendee, etc
List<DefinedValue> connectionStatusTypes = dvService.Queryable()
.Where( dv => dv.DefinedType.Guid == new Guid( Rock.SystemGuid.DefinedType.PERSON_CONNECTION_STATUS ) ).ToList();
// Record status reasons: No Activity, Moved, Deceased, etc
List<DefinedValue> recordStatusReasons = dvService.Queryable()
.Where( dv => dv.DefinedType.Guid == new Guid( Rock.SystemGuid.DefinedType.PERSON_RECORD_STATUS_REASON ) ).ToList();
// Record statuses: Active, Inactive, Pending
int? statusActiveId = dvService.Get( new Guid( Rock.SystemGuid.DefinedValue.PERSON_RECORD_STATUS_ACTIVE ) ).Id;
int? statusInactiveId = dvService.Get( new Guid( Rock.SystemGuid.DefinedValue.PERSON_RECORD_STATUS_INACTIVE ) ).Id;
int? statusPendingId = dvService.Get( new Guid( Rock.SystemGuid.DefinedValue.PERSON_RECORD_STATUS_PENDING ) ).Id;
// Record type: Person
int? personRecordTypeId = dvService.Get( new Guid( Rock.SystemGuid.DefinedValue.PERSON_RECORD_TYPE_PERSON ) ).Id;
// Suffix type: Dr., Jr., II, etc
List<DefinedValue> suffixTypes = dvService.Queryable()
.Where( dv => dv.DefinedType.Guid == new Guid( Rock.SystemGuid.DefinedType.PERSON_SUFFIX ) ).ToList();
// Title type: Mr., Mrs. Dr., etc
List<DefinedValue> titleTypes = dvService.Queryable()
.Where( dv => dv.DefinedType.Guid == new Guid( Rock.SystemGuid.DefinedType.PERSON_TITLE ) ).ToList();
// Note type: Comment
int noteCommentTypeId = new NoteTypeService().Get( new Guid( "7E53487C-D650-4D85-97E2-350EB8332763" ) ).Id;
// Group roles: Adult, Child, others
int adultRoleId = groupTypeRoleService.Get( new Guid( Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_ADULT ) ).Id;
int childRoleId = groupTypeRoleService.Get( new Guid( Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_CHILD ) ).Id;
// Group type: Family
int familyGroupTypeId = GroupTypeCache.GetFamilyGroupType().Id;
// Look up additional Person attributes (existing)
var personAttributes = attributeService.GetByEntityTypeId( PersonEntityTypeId ).ToList();
// Cached F1 attributes: IndividualId, HouseholdId, PreviousChurch, Position, Employer, School
var individualIdAttribute = AttributeCache.Read( personAttributes.FirstOrDefault( a => a.Key == "F1IndividualId" ) );
var householdIdAttribute = AttributeCache.Read( personAttributes.FirstOrDefault( a => a.Key == "F1HouseholdId" ) );
var previousChurchAttribute = AttributeCache.Read( personAttributes.FirstOrDefault( a => a.Key == "PreviousChurch" ) );
var employerAttribute = AttributeCache.Read( personAttributes.FirstOrDefault( a => a.Key == "Employer" ) );
var positionAttribute = AttributeCache.Read( personAttributes.FirstOrDefault( a => a.Key == "Position" ) );
var firstVisitAttribute = AttributeCache.Read( personAttributes.FirstOrDefault( a => a.Key == "FirstVisit" ) );
var schoolAttribute = AttributeCache.Read( personAttributes.FirstOrDefault( a => a.Key == "School" ) );
var membershipDateAttribute = AttributeCache.Read( personAttributes.FirstOrDefault( a => a.Key == "MembershipDate" ) );
int completed = 0;
int totalRows = tableData.Count();
int percentage = ( totalRows - 1 ) / 100 + 1;
ReportProgress( 0, string.Format( "Checking person import ({0:N0} found, {1:N0} already exist).", totalRows, ImportedPeople.Count() ) );
foreach ( var groupedRows in tableData.GroupBy<Row, int?>( r => r["Household_ID"] as int? ) )
{
var familyGroup = new Group();
var householdCampusList = new List<string>();
foreach ( var row in groupedRows )
{
int? individualId = row["Individual_ID"] as int?;
int? householdId = row["Household_ID"] as int?;
if ( GetPersonId( individualId, householdId ) == null )
{
var person = new Person();
person.FirstName = row["First_Name"] as string;
person.MiddleName = row["Middle_Name"] as string;
person.NickName = row["Goes_By"] as string ?? person.FirstName;
person.LastName = row["Last_Name"] as string;
person.BirthDate = row["Date_Of_Birth"] as DateTime?;
person.CreatedByPersonAliasId = ImportPersonAlias.Id;
person.RecordTypeValueId = personRecordTypeId;
int groupRoleId = adultRoleId;
var gender = row["Gender"] as string;
if ( gender != null )
{
person.Gender = (Gender)Enum.Parse( typeof( Gender ), gender );
}
string prefix = row["Prefix"] as string;
if ( prefix != null )
{
prefix = prefix.RemoveSpecialCharacters().Trim();
person.TitleValueId = titleTypes.Where( s => prefix == s.Name.RemoveSpecialCharacters() )
//.........这里部分代码省略.........
示例8: AddVisitorGroupMemberRoles
/// <summary>
/// Adds the visitor group member roles.
/// </summary>
/// <param name="family">The family.</param>
/// <param name="personId">The person id.</param>
protected void AddVisitorGroupMemberRoles( CheckInFamily family, int personId )
{
var rockContext = new RockContext();
var groupService = new GroupService( rockContext );
var groupMemberService = new GroupMemberService( rockContext );
var groupRoleService = new GroupTypeRoleService( rockContext );
int ownerRoleId = groupRoleService.Get( new Guid( Rock.SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_OWNER ) ).Id;
int canCheckInId = groupRoleService.Get( new Guid( Rock.SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_CAN_CHECK_IN ) ).Id;
foreach ( var familyMember in family.People )
{
var group = groupMemberService.Queryable()
.Where( m =>
m.PersonId == familyMember.Person.Id &&
m.GroupRoleId == ownerRoleId )
.Select( m => m.Group )
.FirstOrDefault();
if ( group == null )
{
var role = new GroupTypeRoleService( rockContext ).Get( ownerRoleId );
if ( role != null && role.GroupTypeId.HasValue )
{
var groupMember = new GroupMember();
groupMember.PersonId = familyMember.Person.Id;
groupMember.GroupRoleId = role.Id;
group = new Group();
group.Name = role.GroupType.Name;
group.GroupTypeId = role.GroupTypeId.Value;
group.Members.Add( groupMember );
groupService.Add( group );
}
}
// add the visitor to this group with CanCheckIn
Person.CreateCheckinRelationship( familyMember.Person.Id, personId, CurrentPersonAlias );
}
rockContext.SaveChanges();
}
示例9: MapPerson
/// <summary>
/// Maps the person.
/// </summary>
/// <param name="tableData">The table data.</param>
/// <param name="selectedColumns">The selected columns.</param>
private void MapPerson( IQueryable<Row> tableData, List<string> selectedColumns = null )
{
var lookupContext = new RockContext();
var groupTypeRoleService = new GroupTypeRoleService( lookupContext );
var dvService = new DefinedValueService( lookupContext );
var schoolList = new List<DefinedValue>();
var newSchool = new DefinedValue();
var existingSchoolLookUp = dvService.Queryable()
.Where( dv => dv.DefinedTypeId == 34 ).ToList();
// Marital statuses: Married, Single, Separated, etc
var maritalStatusTypes = DefinedTypeCache.Read( new Guid( Rock.SystemGuid.DefinedType.PERSON_MARITAL_STATUS ), lookupContext ).DefinedValues;
// Connection statuses: Member, Visitor, Attendee, etc
var connectionStatusTypes = DefinedTypeCache.Read( new Guid( Rock.SystemGuid.DefinedType.PERSON_CONNECTION_STATUS ), lookupContext ).DefinedValues;
// Record status reasons: No Activity, Moved, Deceased, etc
var recordStatusReasons = DefinedTypeCache.Read( new Guid( Rock.SystemGuid.DefinedType.PERSON_RECORD_STATUS_REASON ), lookupContext ).DefinedValues;
// Record statuses: Active, Inactive, Pending
int? recordStatusActiveId = DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.PERSON_RECORD_STATUS_ACTIVE ), lookupContext ).Id;
int? recordStatusInactiveId = DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.PERSON_RECORD_STATUS_INACTIVE ), lookupContext ).Id;
int? recordStatusPendingId = DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.PERSON_RECORD_STATUS_PENDING ), lookupContext ).Id;
// Record type: Person
int? personRecordTypeId = DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.PERSON_RECORD_TYPE_PERSON ), lookupContext ).Id;
// Suffix type: Dr., Jr., II, etc
var suffixTypes = DefinedTypeCache.Read( new Guid( Rock.SystemGuid.DefinedType.PERSON_SUFFIX ) ).DefinedValues;
// Title type: Mr., Mrs. Dr., etc
var titleTypes = DefinedTypeCache.Read( new Guid( Rock.SystemGuid.DefinedType.PERSON_TITLE ), lookupContext ).DefinedValues;
// Note type: Comment
int noteCommentTypeId = new NoteTypeService( lookupContext ).Get( new Guid( "7E53487C-D650-4D85-97E2-350EB8332763" ) ).Id;
// Group roles: Owner, Adult, Child, others
GroupTypeRole ownerRole = groupTypeRoleService.Get( new Guid( Rock.SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_OWNER ) );
int adultRoleId = groupTypeRoleService.Get( new Guid( Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_ADULT ) ).Id;
int childRoleId = groupTypeRoleService.Get( new Guid( Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_CHILD ) ).Id;
int inviteeRoleId = groupTypeRoleService.Get( new Guid( Rock.SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_INVITED ) ).Id;
int invitedByRoleId = groupTypeRoleService.Get( new Guid( Rock.SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_INVITED_BY ) ).Id;
int canCheckInRoleId = groupTypeRoleService.Get( new Guid( Rock.SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_CAN_CHECK_IN ) ).Id;
int allowCheckInByRoleId = groupTypeRoleService.Get( new Guid( Rock.SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_ALLOW_CHECK_IN_BY ) ).Id;
// Group type: Family
int familyGroupTypeId = new GroupTypeService( lookupContext ).Get( new Guid( Rock.SystemGuid.GroupType.GROUPTYPE_FAMILY ) ).Id;
// Look up additional Person attributes (existing)
var personAttributes = new AttributeService( lookupContext ).GetByEntityTypeId( PersonEntityTypeId ).ToList();
// Cached F1 attributes: IndividualId, HouseholdId
// Core attributes: PreviousChurch, Position, Employer, School
var individualIdAttribute = AttributeCache.Read( personAttributes.FirstOrDefault( a => a.Key == "F1IndividualId" ) );
var householdIdAttribute = AttributeCache.Read( personAttributes.FirstOrDefault( a => a.Key == "F1HouseholdId" ) );
var previousChurchAttribute = AttributeCache.Read( personAttributes.FirstOrDefault( a => a.Key == "PreviousChurch" ) );
var employerAttribute = AttributeCache.Read( personAttributes.FirstOrDefault( a => a.Key == "Employer" ) );
var positionAttribute = AttributeCache.Read( personAttributes.FirstOrDefault( a => a.Key == "Position" ) );
var firstVisitAttribute = AttributeCache.Read( personAttributes.FirstOrDefault( a => a.Key == "FirstVisit" ) );
var schoolAttribute = AttributeCache.Read( personAttributes.FirstOrDefault( a => a.Key == "School" ) );
var membershipDateAttribute = AttributeCache.Read( personAttributes.FirstOrDefault( a => a.Key == "MembershipDate" ) );
var familyList = new List<Group>();
var visitorList = new List<Group>();
int completed = 0;
int totalRows = tableData.Count();
int percentage = ( totalRows - 1 ) / 100 + 1;
ReportProgress( 0, string.Format( "Verifying person import ({0:N0} found, {1:N0} already exist).", totalRows, ImportedPeople.Count() ) );
foreach ( var groupedRows in tableData.GroupBy<Row, int?>( r => r["Household_ID"] as int? ) )
{
var familyGroup = new Group();
var householdCampusList = new List<string>();
foreach ( var row in groupedRows )
{
bool isFamilyRelationship = true;
string currentCampus = string.Empty;
int? individualId = row["Individual_ID"] as int?;
int? householdId = row["Household_ID"] as int?;
if ( GetPersonAliasId( individualId, householdId ) == null )
{
var person = new Person();
person.FirstName = row["First_Name"] as string;
person.MiddleName = row["Middle_Name"] as string;
person.NickName = row["Goes_By"] as string ?? person.FirstName;
person.LastName = row["Last_Name"] as string;
person.BirthDate = row["Date_Of_Birth"] as DateTime?;
person.CreatedByPersonAliasId = ImportPersonAlias.Id;
person.RecordTypeValueId = personRecordTypeId;
person.ForeignId = individualId.ToString();
int groupRoleId = adultRoleId;
//.........这里部分代码省略.........
示例10: LoadIndividuals
/// <summary>
/// Loads the individual data.
/// </summary>
/// <param name="csvData">The CSV data.</param>
private int LoadIndividuals( CsvDataModel csvData )
{
var lookupContext = new RockContext();
var groupTypeRoleService = new GroupTypeRoleService( lookupContext );
var groupMemberService = new GroupMemberService( lookupContext );
// Marital statuses: Married, Single, Separated, etc
var maritalStatusTypes = DefinedTypeCache.Read( new Guid( Rock.SystemGuid.DefinedType.PERSON_MARITAL_STATUS ), lookupContext ).DefinedValues;
// Connection statuses: Member, Visitor, Attendee, etc
var connectionStatusTypes = DefinedTypeCache.Read( new Guid( Rock.SystemGuid.DefinedType.PERSON_CONNECTION_STATUS ), lookupContext ).DefinedValues;
int memberConnectionStatusId = connectionStatusTypes.FirstOrDefault( dv => dv.Guid == new Guid( Rock.SystemGuid.DefinedValue.PERSON_CONNECTION_STATUS_MEMBER ) ).Id;
int visitorConnectionStatusId = connectionStatusTypes.FirstOrDefault( dv => dv.Guid == new Guid( Rock.SystemGuid.DefinedValue.PERSON_CONNECTION_STATUS_VISITOR ) ).Id;
int attendeeConnectionStatusId = connectionStatusTypes.FirstOrDefault( dv => dv.Guid == new Guid( Rock.SystemGuid.DefinedValue.PERSON_CONNECTION_STATUS_ATTENDEE ) ).Id;
// Suffix type: Dr., Jr., II, etc
var suffixTypes = DefinedTypeCache.Read( new Guid( Rock.SystemGuid.DefinedType.PERSON_SUFFIX ), lookupContext ).DefinedValues;
// Title type: Mr., Mrs. Dr., etc
var titleTypes = DefinedTypeCache.Read( new Guid( Rock.SystemGuid.DefinedType.PERSON_TITLE ), lookupContext ).DefinedValues;
// Record statuses: Active, Inactive, Pending
int? recordStatusActiveId = DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.PERSON_RECORD_STATUS_ACTIVE ), lookupContext ).Id;
int? recordStatusInactiveId = DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.PERSON_RECORD_STATUS_INACTIVE ), lookupContext ).Id;
int? recordStatusPendingId = DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.PERSON_RECORD_STATUS_PENDING ), lookupContext ).Id;
// Deceased record status reason (others available: No Activity, Moved, etc)
var recordStatusDeceasedId = DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.PERSON_RECORD_STATUS_REASON_DECEASED ) ).Id;
// Record type: Person
int? personRecordTypeId = DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.PERSON_RECORD_TYPE_PERSON ), lookupContext ).Id;
// Group roles: Owner, Adult, Child, others
GroupTypeRole ownerRole = groupTypeRoleService.Get( new Guid( Rock.SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_OWNER ) );
int adultRoleId = groupTypeRoleService.Get( new Guid( Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_ADULT ) ).Id;
int childRoleId = groupTypeRoleService.Get( new Guid( Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_CHILD ) ).Id;
// Phone types: Home, Work, Mobile
var numberTypeValues = DefinedTypeCache.Read( new Guid( Rock.SystemGuid.DefinedType.PERSON_PHONE_TYPE ), lookupContext ).DefinedValues;
// Timeline note type id
var noteTimelineTypeId = new NoteTypeService( lookupContext ).Get( new Guid( "7E53487C-D650-4D85-97E2-350EB8332763" ) ).Id;
// School defined type
var schoolDefinedType = DefinedTypeCache.Read( new Guid( "576FF1E2-6225-4565-A16D-230E26167A3D" ) );
// Look up additional Person attributes (existing)
var personAttributes = new AttributeService( lookupContext ).GetByEntityTypeId( PersonEntityTypeId ).ToList();
// Core attributes: PreviousChurch, Position, Employer, School, etc
var previousChurchAttribute = AttributeCache.Read( personAttributes.FirstOrDefault( a => a.Key == "PreviousChurch" ) );
var employerAttribute = AttributeCache.Read( personAttributes.FirstOrDefault( a => a.Key == "Employer" ) );
var positionAttribute = AttributeCache.Read( personAttributes.FirstOrDefault( a => a.Key == "Position" ) );
var firstVisitAttribute = AttributeCache.Read( personAttributes.FirstOrDefault( a => a.Key == "FirstVisit" ) );
var schoolAttribute = AttributeCache.Read( personAttributes.FirstOrDefault( a => a.Key == "School" ) );
var membershipDateAttribute = AttributeCache.Read( personAttributes.FirstOrDefault( a => a.Key == "MembershipDate" ) );
var baptismDateAttribute = AttributeCache.Read( personAttributes.FirstOrDefault( a => a.Key == "BaptismDate" ) );
var facebookAttribute = AttributeCache.Read( personAttributes.FirstOrDefault( a => a.Key == "Facebook" ) );
var twitterAttribute = AttributeCache.Read( personAttributes.FirstOrDefault( a => a.Key == "Twitter" ) );
var instagramAttribute = AttributeCache.Read( personAttributes.FirstOrDefault( a => a.Key == "Instagram" ) );
// Text field type id
int textFieldTypeId = FieldTypeCache.Read( new Guid( Rock.SystemGuid.FieldType.TEXT ), lookupContext ).Id;
// Attribute entity type id
int attributeEntityTypeId = EntityTypeCache.Read( "Rock.Model.Attribute" ).Id;
// Visit info category
var visitInfoCategory = new CategoryService( lookupContext ).GetByEntityTypeId( attributeEntityTypeId )
.Where( c => c.Name == "Visit Information" ).FirstOrDefault();
// Add a Secondary Email attribute if it doesn't exist
var secondaryEmail = personAttributes.FirstOrDefault( a => a.Key == "SecondaryEmail" );
if ( secondaryEmail == null )
{
secondaryEmail = new Rock.Model.Attribute();
secondaryEmail.Key = "SecondaryEmail";
secondaryEmail.Name = "Secondary Email";
secondaryEmail.FieldTypeId = textFieldTypeId;
secondaryEmail.EntityTypeId = PersonEntityTypeId;
secondaryEmail.EntityTypeQualifierValue = string.Empty;
secondaryEmail.EntityTypeQualifierColumn = string.Empty;
secondaryEmail.Description = "The secondary email for this person";
secondaryEmail.DefaultValue = string.Empty;
secondaryEmail.IsMultiValue = false;
secondaryEmail.IsRequired = false;
secondaryEmail.Order = 0;
lookupContext.Attributes.Add( secondaryEmail );
secondaryEmail.Categories.Add( visitInfoCategory );
lookupContext.SaveChanges( true );
}
var secondaryEmailAttribute = AttributeCache.Read( secondaryEmail.Id, lookupContext );
// Add a former name attribute
//.........这里部分代码省略.........