本文整理汇总了C#中Person.GetFamilies方法的典型用法代码示例。如果您正苦于以下问题:C# Person.GetFamilies方法的具体用法?C# Person.GetFamilies怎么用?C# Person.GetFamilies使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Person
的用法示例。
在下文中一共展示了Person.GetFamilies方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SaveLocationToFamilyIfNone
/// <summary>
/// Saves the location to family if none.
/// </summary>
/// <param name="person">The person.</param>
/// <param name="billingLocationId">The billing location identifier.</param>
/// <param name="rockContext">The rock context.</param>
private void SaveLocationToFamilyIfNone( Person person, int billingLocationId, RockContext rockContext )
{
var family = person.GetFamilies(rockContext).FirstOrDefault();
if (family == null) {
return;
}
if ( family.GroupLocations.Any() )
{
return;
}
family.GroupLocations.Add( new GroupLocation()
{
GroupLocationTypeValueId = DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.GROUP_LOCATION_TYPE_HOME ) ).Id,
LocationId = billingLocationId
} );
}
示例2: SavePerson
/// <summary>
/// Saves the person.
/// </summary>
/// <param name="rockContext">The rock context.</param>
/// <param name="person">The person.</param>
/// <param name="familyGuid">The family unique identifier.</param>
/// <param name="campusId">The campus identifier.</param>
/// <param name="location">The location.</param>
/// <param name="adultRoleId">The adult role identifier.</param>
/// <param name="childRoleId">The child role identifier.</param>
/// <param name="multipleFamilyGroupIds">The multiple family group ids.</param>
/// <param name="singleFamilyId">The single family identifier.</param>
/// <returns></returns>
private Person SavePerson( RockContext rockContext, Person person, Guid familyGuid, int? campusId, Location location, int adultRoleId, int childRoleId,
Dictionary<Guid, int> multipleFamilyGroupIds, ref int? singleFamilyId )
{
int? familyId = null;
if ( person.Id > 0 )
{
rockContext.SaveChanges();
// Set the family guid for any other registrants that were selected to be in the same family
var family = person.GetFamilies( rockContext ).FirstOrDefault();
if ( family != null )
{
familyId = family.Id;
multipleFamilyGroupIds.AddOrIgnore( familyGuid, family.Id );
if ( !singleFamilyId.HasValue )
{
singleFamilyId = family.Id;
}
}
}
else
{
// If we've created the family aready for this registrant, add them to it
if (
( RegistrationTemplate.RegistrantsSameFamily == RegistrantsSameFamily.Ask && multipleFamilyGroupIds.ContainsKey( familyGuid ) ) ||
( RegistrationTemplate.RegistrantsSameFamily == RegistrantsSameFamily.Yes && singleFamilyId.HasValue )
)
{
// Add person to existing family
var age = person.Age;
int familyRoleId = age.HasValue && age < 18 ? childRoleId : adultRoleId;
familyId = RegistrationTemplate.RegistrantsSameFamily == RegistrantsSameFamily.Ask ?
multipleFamilyGroupIds[familyGuid] :
singleFamilyId.Value;
PersonService.AddPersonToFamily( person, true, multipleFamilyGroupIds[familyGuid], familyRoleId, rockContext );
}
// otherwise create a new family
else
{
// Create Person/Family
var familyGroup = PersonService.SaveNewPerson( person, rockContext, campusId, false );
if ( familyGroup != null )
{
familyId = familyGroup.Id;
// Store the family id for next person
multipleFamilyGroupIds.AddOrIgnore( familyGuid, familyGroup.Id );
if ( !singleFamilyId.HasValue )
{
singleFamilyId = familyGroup.Id;
}
}
}
}
if ( familyId.HasValue && location != null )
{
var homeLocationType = DefinedValueCache.Read( Rock.SystemGuid.DefinedValue.GROUP_LOCATION_TYPE_HOME.AsGuid() );
if ( homeLocationType != null )
{
var familyGroup = new GroupService( rockContext ).Get( familyId.Value );
if ( familyGroup != null )
{
GroupService.AddNewGroupAddress(
rockContext,
familyGroup,
Rock.SystemGuid.DefinedValue.GROUP_LOCATION_TYPE_HOME,
location.Street1, location.Street2, location.City, location.State, location.PostalCode, location.Country, true );
}
}
}
return new PersonService( rockContext ).Get( person.Id );
}