本文整理汇总了C#中Rock.Model.AttributeValueService.FirstOrDefault方法的典型用法代码示例。如果您正苦于以下问题:C# AttributeValueService.FirstOrDefault方法的具体用法?C# AttributeValueService.FirstOrDefault怎么用?C# AttributeValueService.FirstOrDefault使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rock.Model.AttributeValueService
的用法示例。
在下文中一共展示了AttributeValueService.FirstOrDefault方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetPersonId
/// <summary>
/// Checks if this person or business has been imported and returns the Rock.Person Id
/// </summary>
/// <param name="individualId">The individual identifier.</param>
/// <param name="householdId">The household identifier.</param>
/// <returns></returns>
private int? GetPersonId( int? individualId = null, int? householdId = null )
{
var existingPerson = ImportedPeople.FirstOrDefault( p => p.IndividualId == individualId && p.HouseholdId == householdId );
if ( existingPerson != null )
{
return existingPerson.PersonId;
}
else
{
int lookupAttributeId = individualId.HasValue ? IndividualAttributeId : HouseholdAttributeId;
string lookupValueId = individualId.HasValue ? individualId.ToString() : householdId.ToString();
var lookup = new AttributeValueService().Queryable()
.Where( av => av.AttributeId == lookupAttributeId && av.Value == lookupValueId );
var lookupPerson = lookup.FirstOrDefault();
if ( lookupPerson != null )
{
ImportedPeople.Add( new ImportedPerson()
{
PersonId = lookupPerson.EntityId,
HouseholdId = householdId,
IndividualId = individualId
} );
return lookupPerson.EntityId;
}
}
return null;
}