本文整理汇总了C#中Rock.Model.AttributeService.Queryable方法的典型用法代码示例。如果您正苦于以下问题:C# AttributeService.Queryable方法的具体用法?C# AttributeService.Queryable怎么用?C# AttributeService.Queryable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rock.Model.AttributeService
的用法示例。
在下文中一共展示了AttributeService.Queryable方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MapActivityMinistry
/// <summary>
/// Maps the activity ministry.
/// </summary>
/// <param name="tableData">The table data.</param>
/// <returns></returns>
private void MapActivityMinistry( IQueryable<Row> tableData )
{
int groupEntityTypeId = EntityTypeCache.Read( "Rock.Model.Group" ).Id;
var attributeService = new AttributeService();
// Add an Attribute for the unique F1 Ministry Id
var ministryAttributeId = attributeService.Queryable().Where( a => a.EntityTypeId == groupEntityTypeId
&& a.Key == "F1MinistryId" ).Select( a => a.Id ).FirstOrDefault();
if ( ministryAttributeId == 0 )
{
var newMinistryAttribute = new Rock.Model.Attribute();
newMinistryAttribute.Key = "F1MinistryId";
newMinistryAttribute.Name = "F1 Ministry Id";
newMinistryAttribute.FieldTypeId = IntegerFieldTypeId;
newMinistryAttribute.EntityTypeId = groupEntityTypeId;
newMinistryAttribute.EntityTypeQualifierValue = string.Empty;
newMinistryAttribute.EntityTypeQualifierColumn = string.Empty;
newMinistryAttribute.Description = "The FellowshipOne identifier for the ministry that was imported";
newMinistryAttribute.DefaultValue = string.Empty;
newMinistryAttribute.IsMultiValue = false;
newMinistryAttribute.IsRequired = false;
newMinistryAttribute.Order = 0;
attributeService.Add( newMinistryAttribute, ImportPersonAlias );
attributeService.Save( newMinistryAttribute, ImportPersonAlias );
ministryAttributeId = newMinistryAttribute.Id;
}
// Get previously imported Ministries
var importedMinistries = new AttributeValueService().GetByAttributeId( ministryAttributeId )
.Select( av => new { RLCId = av.Value.AsType<int?>(), LocationId = av.EntityId } )
.ToDictionary( t => t.RLCId, t => t.LocationId );
foreach ( var row in tableData )
{
int? ministryId = row["Ministry_ID"] as int?;
if ( ministryId != null && !importedMinistries.ContainsKey( ministryId ) )
{
// Activity_ID
// Ministry_Name
// Activity_Name
// Ministry_Active
// Activity_Active
}
}
}
示例2: GetGroupMemberAttributes
/// <summary>
/// Gets the Attributes for a Group Member of a specific Group Type.
/// </summary>
/// <returns></returns>
private List<EntityField> GetGroupMemberAttributes()
{
var entityAttributeFields = new Dictionary<string, EntityField>();
var context = new RockContext();
var attributeService = new AttributeService( context );
var groupTypeService = new GroupTypeService( context );
var groupMemberEntityTypeId = EntityTypeCache.GetId( typeof(Model.GroupMember) );
var groupMemberAttributes = attributeService.Queryable()
.AsNoTracking()
.Where( a => a.EntityTypeId == groupMemberEntityTypeId )
.Join( groupTypeService.Queryable(), a => a.EntityTypeQualifierValue, gt => gt.Id.ToString(),
( a, gt ) =>
new
{
Attribute = a,
AttributeKey = a.Key,
FieldTypeName = a.FieldType.Name,
a.FieldTypeId,
AttributeName = a.Name,
GroupTypeName = gt.Name
} )
.GroupBy( x => x.AttributeName )
.ToList();
foreach (var attributesByName in groupMemberAttributes)
{
var attributeNameAndTypeGroups = attributesByName.GroupBy( x => x.FieldTypeId ).ToList();
bool requiresTypeQualifier = ( attributeNameAndTypeGroups.Count > 1 );
foreach (var attributeNameAndTypeGroup in attributeNameAndTypeGroups)
{
foreach (var attribute in attributeNameAndTypeGroup)
{
string fieldKey;
string fieldName;
if (requiresTypeQualifier)
{
fieldKey = attribute.AttributeName + "_" + attribute.FieldTypeId;
fieldName = string.Format( "{0} [{1}]", attribute.AttributeName, attribute.FieldTypeName );
}
else
{
fieldName = attribute.AttributeName;
fieldKey = attribute.AttributeName;
}
if (entityAttributeFields.ContainsKey( fieldKey ))
{
continue;
}
var attributeCache = AttributeCache.Read( attribute.Attribute );
var entityField = EntityHelper.GetEntityFieldForAttribute( attributeCache );
entityField.Title = fieldName;
entityField.AttributeGuid = null;
entityAttributeFields.Add( fieldKey, entityField );
}
}
}
int index = 0;
var sortedFields = new List<EntityField>();
foreach (var entityProperty in entityAttributeFields.Values.OrderBy( p => p.Title ).ThenBy( p => p.Name ))
{
entityProperty.Index = index;
index++;
sortedFields.Add( entityProperty );
}
return sortedFields;
}
示例3: SaveAttributeEdits
/// <summary>
/// Saves any attribute edits made using an Attribute Editor control
/// </summary>
/// <param name="edtAttribute">The edt attribute.</param>
/// <param name="entityTypeId">The entity type identifier.</param>
/// <param name="entityTypeQualifierColumn">The entity type qualifier column.</param>
/// <param name="entityTypeQualifierValue">The entity type qualifier value.</param>
/// <param name="rockContext">The rock context.</param>
/// <returns></returns>
/// <remarks>
/// If a rockContext value is included, this method will save any previous changes made to the context
/// </remarks>
public static Rock.Model.Attribute SaveAttributeEdits( AttributeEditor edtAttribute, int? entityTypeId, string entityTypeQualifierColumn, string entityTypeQualifierValue, RockContext rockContext = null )
{
// Create and update a new attribute object with new values
var newAttribute = new Rock.Model.Attribute();
edtAttribute.GetAttributeProperties( newAttribute );
rockContext = rockContext ?? new RockContext();
var internalAttributeService = new AttributeService( rockContext );
Rock.Model.Attribute attribute = null;
if ( newAttribute.Id > 0 )
{
attribute = internalAttributeService.Get( newAttribute.Id );
}
if ( attribute == null )
{
newAttribute.Order = internalAttributeService.Queryable().Max( a => a.Order ) + 1;
}
else
{
newAttribute.Order = attribute.Order;
}
return SaveAttributeEdits( newAttribute, entityTypeId, entityTypeQualifierColumn, entityTypeQualifierValue, rockContext );
}
示例4: LoadAttributes
/// <summary>
/// Loads the <see cref="P:IHasAttributes.Attributes" /> and <see cref="P:IHasAttributes.AttributeValues" /> of any <see cref="IHasAttributes" /> object
/// </summary>
/// <param name="entity">The item.</param>
/// <param name="rockContext">The rock context.</param>
public static void LoadAttributes( Rock.Attribute.IHasAttributes entity, RockContext rockContext )
{
if ( entity != null )
{
Dictionary<string, PropertyInfo> properties = new Dictionary<string, PropertyInfo>();
Type entityType = entity.GetType();
if ( entityType.Namespace == "System.Data.Entity.DynamicProxies" )
entityType = entityType.BaseType;
rockContext = rockContext ?? new RockContext();
// Check for group type attributes
var groupTypeIds = new List<int>();
if ( entity is GroupMember || entity is Group || entity is GroupType )
{
// Can't use GroupTypeCache here since it loads attributes and would result in a recursive stack overflow situation
var groupTypeService = new GroupTypeService( rockContext );
GroupType groupType = null;
if ( entity is GroupMember )
{
var group = ( (GroupMember)entity ).Group ?? new GroupService( rockContext )
.Queryable().AsNoTracking().FirstOrDefault(g => g.Id == ( (GroupMember)entity ).GroupId );
if ( group != null )
{
groupType = group.GroupType ?? groupTypeService
.Queryable().AsNoTracking().FirstOrDefault( t => t.Id == group.GroupTypeId );
}
}
else if ( entity is Group )
{
groupType = ( (Group)entity ).GroupType ?? groupTypeService
.Queryable().AsNoTracking().FirstOrDefault( t => t.Id == ( (Group)entity ).GroupTypeId );
}
else
{
groupType = ( (GroupType)entity );
}
while ( groupType != null )
{
groupTypeIds.Insert( 0, groupType.Id );
// Check for inherited group type id's
if ( groupType.InheritedGroupTypeId.HasValue )
{
groupType = groupType.InheritedGroupType ?? groupTypeService
.Queryable().AsNoTracking().FirstOrDefault( t => t.Id == ( groupType.InheritedGroupTypeId ?? 0 ) );
}
else
{
groupType = null;
}
}
}
foreach ( PropertyInfo propertyInfo in entityType.GetProperties() )
properties.Add( propertyInfo.Name.ToLower(), propertyInfo );
Rock.Model.AttributeService attributeService = new Rock.Model.AttributeService( rockContext );
Rock.Model.AttributeValueService attributeValueService = new Rock.Model.AttributeValueService( rockContext );
var inheritedAttributes = new Dictionary<int, List<Rock.Web.Cache.AttributeCache>>();
if ( groupTypeIds.Any() )
{
groupTypeIds.ForEach( g => inheritedAttributes.Add( g, new List<Rock.Web.Cache.AttributeCache>() ) );
}
else
{
inheritedAttributes.Add( 0, new List<Rock.Web.Cache.AttributeCache>() );
}
var attributes = new List<Rock.Web.Cache.AttributeCache>();
// Get all the attributes that apply to this entity type and this entity's properties match any attribute qualifiers
var entityTypeCache = Rock.Web.Cache.EntityTypeCache.Read( entityType);
if ( entityTypeCache != null )
{
int entityTypeId = entityTypeCache.Id;
foreach ( var attribute in attributeService.Queryable()
.AsNoTracking()
.Where( a => a.EntityTypeId == entityTypeCache.Id )
.Select( a => new
{
a.Id,
a.EntityTypeQualifierColumn,
a.EntityTypeQualifierValue
}
) )
{
// group type ids exist (entity is either GroupMember, Group, or GroupType) and qualifier is for a group type id
if ( groupTypeIds.Any() && (
( entity is GroupMember && string.Compare( attribute.EntityTypeQualifierColumn, "GroupTypeId", true ) == 0 ) ||
//.........这里部分代码省略.........
示例5: GetData
private IQueryable<Rock.Model.Attribute> GetData( RockContext rockContext )
{
IQueryable<Rock.Model.Attribute> query = null;
AttributeService attributeService = new AttributeService( rockContext );
if ( _configuredType )
{
query = attributeService.Get( _entityTypeId, _entityQualifierColumn, _entityQualifierValue );
}
else
{
int? entityTypeId = rFilter.GetUserPreference( "Entity Type" ).AsIntegerOrNull();
if ( entityTypeId.HasValue )
{
if ( entityTypeId.Value == 0 )
{
// Global Attributes
query = attributeService.GetByEntityTypeId( null );
}
else
{
query = attributeService.GetByEntityTypeId( entityTypeId );
}
}
else
{
// All entity attribute
query = attributeService.Queryable()
.Where( a =>
( a.EntityType != null && a.EntityType.IsEntity ) || // Entity Attributes
( a.EntityType == null && a.EntityTypeQualifierColumn == "" && a.EntityTypeQualifierValue == "" ) // Global Attributes
);
}
}
// if filtering by block setting of categories
if (!string.IsNullOrWhiteSpace( GetAttributeValue( "CategoryFilter" ) ) )
{
try {
var categoryGuids = GetAttributeValue( "CategoryFilter" ).Split( ',' ).Select( Guid.Parse ).ToList();
query = query.Where( a => a.Categories.Any( c => categoryGuids.Contains( c.Guid ) ) );
}
catch { }
}
var selectedCategoryIds = new List<int>();
rFilter.GetUserPreference( "Categories" ).SplitDelimitedValues().ToList().ForEach( s => selectedCategoryIds.Add( int.Parse( s ) ) );
if ( selectedCategoryIds.Any() )
{
query = query.Where( a => a.Categories.Any( c => selectedCategoryIds.Contains( c.Id ) ) );
}
if ( _enableOrdering )
{
query = query.OrderBy( a => a.Order );
}
else
{
SortProperty sortProperty = rGrid.SortProperty;
if ( sortProperty != null )
{
query = query.Sort( sortProperty );
}
else
{
query = query.OrderBy( a => a.Key );
}
}
return query;
}
示例6: MapRLC
/// <summary>
/// Maps the RLC data to rooms, locations & classes
/// </summary>
/// <param name="tableData">The table data.</param>
/// <returns></returns>
private void MapRLC( IQueryable<Row> tableData )
{
int locationEntityTypeId = EntityTypeCache.Read( "Rock.Model.Location" ).Id;
int groupEntityTypeId = EntityTypeCache.Read( "Rock.Model.Group" ).Id;
var attributeService = new AttributeService();
// Add an Attribute for the unique F1 RLC Id
var rlcAttributeId = attributeService.Queryable().Where( a => a.EntityTypeId == locationEntityTypeId
&& a.Key == "F1RLCId" ).Select( a => a.Id ).FirstOrDefault();
if ( rlcAttributeId == 0 )
{
var newRLCAttribute = new Rock.Model.Attribute();
newRLCAttribute.Key = "F1RLCId";
newRLCAttribute.Name = "F1 RLC Id";
newRLCAttribute.FieldTypeId = IntegerFieldTypeId;
newRLCAttribute.EntityTypeId = locationEntityTypeId;
newRLCAttribute.EntityTypeQualifierValue = string.Empty;
newRLCAttribute.EntityTypeQualifierColumn = string.Empty;
newRLCAttribute.Description = "The FellowshipOne identifier for the RLC (Room/Location/Class) that was imported";
newRLCAttribute.DefaultValue = string.Empty;
newRLCAttribute.IsMultiValue = false;
newRLCAttribute.IsRequired = false;
newRLCAttribute.Order = 0;
attributeService.Add( newRLCAttribute, ImportPersonAlias );
attributeService.Save( newRLCAttribute, ImportPersonAlias );
rlcAttributeId = newRLCAttribute.Id;
}
// Add an Attribute for the unique F1 Activity Id
var activityAttributeId = attributeService.Queryable().Where( a => a.EntityTypeId == locationEntityTypeId
&& a.Key == "F1ActivityId" ).Select( a => a.Id ).FirstOrDefault();
if ( rlcAttributeId == 0 )
{
var newActivityAttribute = new Rock.Model.Attribute();
newActivityAttribute.Key = "F1ActivityId";
newActivityAttribute.Name = "F1 Activity Id";
newActivityAttribute.FieldTypeId = IntegerFieldTypeId;
newActivityAttribute.EntityTypeId = locationEntityTypeId;
newActivityAttribute.EntityTypeQualifierValue = string.Empty;
newActivityAttribute.EntityTypeQualifierColumn = string.Empty;
newActivityAttribute.Description = "The FellowshipOne identifier for the activity that was imported";
newActivityAttribute.DefaultValue = string.Empty;
newActivityAttribute.IsMultiValue = false;
newActivityAttribute.IsRequired = false;
newActivityAttribute.Order = 0;
attributeService.Add( newActivityAttribute, ImportPersonAlias );
attributeService.Save( newActivityAttribute, ImportPersonAlias );
activityAttributeId = newActivityAttribute.Id;
}
var rlcAttribute = AttributeCache.Read( rlcAttributeId );
var activityAttribute = AttributeCache.Read( activityAttributeId );
// Get any previously imported RLCs
var importedRLC = new AttributeValueService().GetByAttributeId( rlcAttributeId )
.Select( av => new { RLCId = av.Value.AsType<int?>(), LocationId = av.EntityId } )
.ToDictionary( t => t.RLCId, t => t.LocationId );
ImportedActivities = new AttributeValueService().GetByAttributeId( activityAttributeId )
.Select( av => new { ActivityId = av.Value.AsType<int?>(), GroupId = av.EntityId } )
.ToDictionary( t => t.ActivityId, t => t.GroupId );
foreach ( var row in tableData )
{
int? rlcId = row["RLC_ID"] as int?;
if ( rlcId != null && !importedRLC.ContainsKey( rlcId ) )
{
// Activity_ID
// RLC_Name
// Activity_Group_ID
// Start_Age_Date
// End_Age_Date
// Is_Active
// Room_Code
// Room_Desc
// Room_Name
// Max_Capacity
// Building_Name
}
}
}
示例7: LoadExistingRockData
/// <summary>
/// Loads Rock data that's used globally by the transform
/// </summary>
private void LoadExistingRockData()
{
var attributeValueService = new AttributeValueService();
var attributeService = new AttributeService();
IntegerFieldTypeId = FieldTypeCache.Read( new Guid( Rock.SystemGuid.FieldType.INTEGER ) ).Id;
TextFieldTypeId = FieldTypeCache.Read( new Guid( Rock.SystemGuid.FieldType.TEXT ) ).Id;
PersonEntityTypeId = EntityTypeCache.Read( "Rock.Model.Person" ).Id;
BatchEntityTypeId = EntityTypeCache.Read( "Rock.Model.FinancialBatch" ).Id;
var personAttributes = attributeService.GetByEntityTypeId( PersonEntityTypeId ).ToList();
var householdAttribute = personAttributes.FirstOrDefault( a => a.Key == "F1HouseholdId" );
if ( householdAttribute == null )
{
householdAttribute = new Rock.Model.Attribute();
householdAttribute.Key = "F1HouseholdId";
householdAttribute.Name = "F1 Household Id";
householdAttribute.FieldTypeId = IntegerFieldTypeId;
householdAttribute.EntityTypeId = PersonEntityTypeId;
householdAttribute.EntityTypeQualifierValue = string.Empty;
householdAttribute.EntityTypeQualifierColumn = string.Empty;
householdAttribute.Description = "The FellowshipOne household identifier for the person that was imported";
householdAttribute.DefaultValue = string.Empty;
householdAttribute.IsMultiValue = false;
householdAttribute.IsRequired = false;
householdAttribute.Order = 0;
attributeService.Add( householdAttribute, ImportPersonAlias );
attributeService.Save( householdAttribute, ImportPersonAlias );
personAttributes.Add( householdAttribute );
}
var individualAttribute = personAttributes.FirstOrDefault( a => a.Key == "F1IndividualId" );
if ( individualAttribute == null )
{
individualAttribute = new Rock.Model.Attribute();
individualAttribute.Key = "F1IndividualId";
individualAttribute.Name = "F1 Individual Id";
individualAttribute.FieldTypeId = IntegerFieldTypeId;
individualAttribute.EntityTypeId = PersonEntityTypeId;
individualAttribute.EntityTypeQualifierValue = string.Empty;
individualAttribute.EntityTypeQualifierColumn = string.Empty;
individualAttribute.Description = "The FellowshipOne individual identifier for the person that was imported";
individualAttribute.DefaultValue = string.Empty;
individualAttribute.IsMultiValue = false;
individualAttribute.IsRequired = false;
individualAttribute.Order = 0;
attributeService.Add( individualAttribute, ImportPersonAlias );
attributeService.Save( individualAttribute, ImportPersonAlias );
personAttributes.Add( individualAttribute );
}
IndividualAttributeId = individualAttribute.Id;
HouseholdAttributeId = householdAttribute.Id;
ReportProgress( 0, "Checking for existing people..." );
var listHouseholdId = attributeValueService.GetByAttributeId( householdAttribute.Id ).Select( av => new { PersonId = av.EntityId, HouseholdId = av.Value } ).ToList();
var listIndividualId = attributeValueService.GetByAttributeId( individualAttribute.Id ).Select( av => new { PersonId = av.EntityId, IndividualId = av.Value } ).ToList();
ImportedPeople = listHouseholdId.GroupJoin( listIndividualId, household => household.PersonId,
individual => individual.PersonId, ( household, individual ) => new ImportedPerson
{
PersonId = household.PersonId,
HouseholdId = household.HouseholdId.AsType<int?>(),
IndividualId = individual.Select( i => i.IndividualId.AsType<int?>() ).FirstOrDefault()
} ).ToList();
var batchAttribute = attributeService.Queryable().FirstOrDefault( a => a.EntityTypeId == BatchEntityTypeId
&& a.Key == "F1BatchId" );
if ( batchAttribute == null )
{
batchAttribute = new Rock.Model.Attribute();
batchAttribute.Key = "F1BatchId";
batchAttribute.Name = "F1 Batch Id";
batchAttribute.FieldTypeId = IntegerFieldTypeId;
batchAttribute.EntityTypeId = BatchEntityTypeId;
batchAttribute.EntityTypeQualifierValue = string.Empty;
batchAttribute.EntityTypeQualifierColumn = string.Empty;
batchAttribute.Description = "The FellowshipOne identifier for the batch that was imported";
batchAttribute.DefaultValue = string.Empty;
batchAttribute.IsMultiValue = false;
batchAttribute.IsRequired = false;
batchAttribute.Order = 0;
attributeService.Add( batchAttribute, ImportPersonAlias );
attributeService.Save( batchAttribute, ImportPersonAlias );
}
BatchAttributeId = batchAttribute.Id;
ReportProgress( 0, "Checking for existing contributions..." );
ImportedBatches = new AttributeValueService().GetByAttributeId( batchAttribute.Id )
.Select( av => new { F1BatchId = av.Value.AsType<int?>(), RockBatchId = av.EntityId } )
.ToDictionary( t => t.F1BatchId, t => t.RockBatchId );
//.........这里部分代码省略.........
示例8: MapContribution
/// <summary>
/// Maps the contribution.
/// </summary>
/// <param name="tableData">The table data.</param>
/// <param name="selectedColumns">The selected columns.</param>
private void MapContribution( IQueryable<Row> tableData, List<string> selectedColumns = null )
{
int transactionEntityTypeId = EntityTypeCache.Read( "Rock.Model.FinancialTransaction" ).Id;
var accountService = new FinancialAccountService();
var attributeService = new AttributeService();
var transactionTypeContributionId = DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.TRANSACTION_TYPE_CONTRIBUTION ) ).Id;
int currencyTypeACH = DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.CURRENCY_TYPE_ACH ) ).Id;
int currencyTypeCash = DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.CURRENCY_TYPE_CASH ) ).Id;
int currencyTypeCheck = DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.CURRENCY_TYPE_CHECK ) ).Id;
int currencyTypeCreditCard = DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.CURRENCY_TYPE_CREDIT_CARD ) ).Id;
List<DefinedValue> refundReasons = new DefinedValueService().Queryable().Where( dv => dv.DefinedType.Guid == new Guid( Rock.SystemGuid.DefinedType.FINANCIAL_TRANSACTION_REFUND_REASON ) ).ToList();
List<FinancialPledge> pledgeList = new FinancialPledgeService().Queryable().ToList();
List<FinancialAccount> accountList = accountService.Queryable().ToList();
// Add an Attribute for the unique F1 Contribution Id
int contributionAttributeId = attributeService.Queryable().Where( a => a.EntityTypeId == transactionEntityTypeId
&& a.Key == "F1ContributionId" ).Select( a => a.Id ).FirstOrDefault();
if ( contributionAttributeId == 0 )
{
var newContributionAttribute = new Rock.Model.Attribute();
newContributionAttribute.Key = "F1ContributionId";
newContributionAttribute.Name = "F1 Contribution Id";
newContributionAttribute.FieldTypeId = IntegerFieldTypeId;
newContributionAttribute.EntityTypeId = transactionEntityTypeId;
newContributionAttribute.EntityTypeQualifierValue = string.Empty;
newContributionAttribute.EntityTypeQualifierColumn = string.Empty;
newContributionAttribute.Description = "The FellowshipOne identifier for the contribution that was imported";
newContributionAttribute.DefaultValue = string.Empty;
newContributionAttribute.IsMultiValue = false;
newContributionAttribute.IsRequired = false;
newContributionAttribute.Order = 0;
attributeService.Add( newContributionAttribute, ImportPersonAlias );
attributeService.Save( newContributionAttribute, ImportPersonAlias );
contributionAttributeId = newContributionAttribute.Id;
}
var contributionAttribute = AttributeCache.Read( contributionAttributeId );
// Get all imported contributions
var importedContributions = new AttributeValueService().GetByAttributeId( contributionAttributeId )
.Select( av => new { ContributionId = av.Value.AsType<int?>(), TransactionId = av.EntityId } )
.ToDictionary( t => t.ContributionId, t => t.TransactionId );
// List for batching new contributions
var newTransactions = new List<FinancialTransaction>();
int completed = 0;
int totalRows = tableData.Count();
int percentage = ( totalRows - 1 ) / 100 + 1;
ReportProgress( 0, string.Format( "Checking contribution import ({0:N0} found, {1:N0} already exist).", totalRows, importedContributions.Count() ) );
foreach ( var row in tableData )
{
int? individualId = row["Individual_ID"] as int?;
int? householdId = row["Household_ID"] as int?;
int? contributionId = row["ContributionID"] as int?;
if ( contributionId != null && !importedContributions.ContainsKey( contributionId ) )
{
var transaction = new FinancialTransaction();
transaction.TransactionTypeValueId = transactionTypeContributionId;
transaction.AuthorizedPersonId = GetPersonId( individualId, householdId );
transaction.CreatedByPersonAliasId = ImportPersonAlias.Id;
transaction.AuthorizedPersonId = GetPersonId( individualId, householdId );
string summary = row["Memo"] as string;
if ( summary != null )
{
transaction.Summary = summary;
}
int? batchId = row["BatchID"] as int?;
if ( batchId != null && ImportedBatches.Any( b => b.Key == batchId ) )
{
transaction.BatchId = ImportedBatches.FirstOrDefault( b => b.Key == batchId ).Value;
}
DateTime? receivedDate = row["Received_Date"] as DateTime?;
if ( receivedDate != null )
{
transaction.TransactionDateTime = receivedDate;
transaction.CreatedDateTime = receivedDate;
}
bool isTypeNonCash = false;
string contributionType = row["Contribution_Type_Name"] as string;
if ( contributionType != null )
{
if ( contributionType == "ACH" )
{
//.........这里部分代码省略.........
示例9: ProcessConfirmation
//.........这里部分代码省略.........
return false;
}
}
tdTransactionCodeReceipt.Description = TransactionCode;
tdTransactionCodeReceipt.Visible = !string.IsNullOrWhiteSpace( TransactionCode );
tdScheduleId.Description = ScheduleId;
tdScheduleId.Visible = !string.IsNullOrWhiteSpace( ScheduleId );
tdNameReceipt.Description = paymentInfo.FullName;
tdPhoneReceipt.Description = paymentInfo.Phone;
tdEmailReceipt.Description = paymentInfo.Email;
tdAddressReceipt.Description = string.Format( "{0} {1}, {2} {3}", paymentInfo.Street1, paymentInfo.City, paymentInfo.State, paymentInfo.PostalCode );
rptAccountListReceipt.DataSource = SelectedAccounts.Where( a => a.Amount != 0 );
rptAccountListReceipt.DataBind();
tdTotalReceipt.Description = paymentInfo.Amount.ToString( "C" );
tdPaymentMethodReceipt.Description = paymentInfo.CurrencyTypeValue.Description;
tdAccountNumberReceipt.Description = paymentInfo.MaskedNumber;
tdWhenReceipt.Description = schedule != null ? schedule.ToString() : "Today";
// If there was a transaction code returned and this was not already created from a previous saved account,
// show the option to save the account.
if ( !( paymentInfo is ReferencePaymentInfo ) && !string.IsNullOrWhiteSpace( TransactionCode ) && gateway.SupportsSavedAccount( paymentInfo.CurrencyTypeValue ) )
{
cbSaveAccount.Visible = true;
pnlSaveAccount.Visible = true;
txtSaveAccount.Visible = true;
// If current person does not have a login, have them create a username and password
phCreateLogin.Visible = !new UserLoginService( rockContext ).GetByPersonId( person.Id ).Any();
}
else if ( !new UserLoginService( rockContext ).GetByPersonId( person.Id ).Any() )
{
pnlSaveAccount.Visible = true;
phCreateLogin.Visible = true;
cbSaveAccount.Visible = false;
txtSaveAccount.Visible = false;
}
else
{
pnlSaveAccount.Visible = false;
}
if ( PageParameter( "argsd" ) == "1" )
{
var rc = new RockContext();
var ats = new AttributeService( rc );
var argsd = ats.Queryable().Where( x => x.Key == "AutomatedRecurringGiftSetupDate" ).FirstOrDefault();
if ( argsd == null )
{
argsd = new Rock.Model.Attribute();
argsd.FieldTypeId = 85;
argsd.EntityTypeId = 15;
argsd.Key = "AutomatedRecurringGiftSetupDate";
argsd.Name = "Automated Recurring Gift Setup Date";
argsd.Guid = Guid.NewGuid();
argsd.CreatedDateTime = argsd.ModifiedDateTime = DateTime.Now;
ats.Add( argsd );
rc.SaveChanges();
rc = new RockContext();
ats = new AttributeService( rc );
argsd = ats.Queryable().Where( x => x.Key == "AutomatedRecurringGiftSetupDate" ).FirstOrDefault();
}
if ( argsd != null )
{
var atvs = new AttributeValueService( rc );
var argsdVal = atvs.Queryable().Where( x => x.AttributeId == argsd.Id && x.EntityId == person.Id ).FirstOrDefault();
if ( argsdVal == null )
{
argsdVal = new Rock.Model.AttributeValue();
argsdVal.AttributeId = argsd.Id;
argsdVal.EntityId = person.Id;
argsdVal.Value = DateTime.Now.ToString( "o" );
argsdVal.Guid = Guid.NewGuid();
argsdVal.CreatedDateTime = argsdVal.ModifiedDateTime = DateTime.Now;
atvs.Add( argsdVal );
rc.SaveChanges();
}
else
{
argsdVal.Value = DateTime.Now.ToString( "o" );
rc.SaveChanges();
}
}
}
return true;
}
else
{
pnlDupWarning.Visible = true;
divActions.Visible = false;
errorMessage = string.Empty;
return false;
}
}
示例10: MapIndividualGiftedness
/// <summary>
/// Maps the Individual Giftedness.
/// </summary>
/// <param name="tableData">The table data.</param>
private void MapIndividualGiftedness( IQueryable<Row> tableData )
{
var lookupContext = new RockContext();
var attributeService = new AttributeService( lookupContext );
int rank1Id = attributeService.Queryable().Where( a => a.Key == "Rank1" ).FirstOrDefault().Id;
int rank2Id = attributeService.Queryable().Where( a => a.Key == "Rank2" ).FirstOrDefault().Id;
int rank3Id = attributeService.Queryable().Where( a => a.Key == "Rank3" ).FirstOrDefault().Id;
int rank4Id = attributeService.Queryable().Where( a => a.Key == "Rank4" ).FirstOrDefault().Id;
int completed = 0;
int totalRows = tableData.Count();
int percentage = ( totalRows - 1 ) / 100 + 1;
ReportProgress( 0, string.Format( "Verifying Giftedness Program import ({0:N0} found).", totalRows ) );
var newAttributeValueList = new List<AttributeValue>();
foreach ( var row in tableData )
{
int? individualId = row["Individual_ID"] as int?;
int personId = (int)GetPersonAliasId( individualId );
var newAttributeValue = new AttributeValue();
int? rank = row["Rank"] as int?;
int rankId = 0;
//not everyone has all 4 ranks, some are missing the fourth and that was causing it to run in the below if condition and try to create a duplicate record.
if ( rank == 1 ) { rankId = rank1Id; }
if ( rank == 2 ) { rankId = rank2Id; }
if ( rank == 3 ) { rankId = rank3Id; }
if ( rank == 4 ) { rankId = rank4Id; }
if ( personId != 0 && rankId != 0 )
{
var attributeValueService = new AttributeValueService( lookupContext );
//checks if they are in the database already or if there is a record currently in the newAttributeValueList
if ( attributeValueService.Queryable().Where( a => a.AttributeId == rankId && a.EntityId == personId ).FirstOrDefault() == null && newAttributeValueList.Find(a => a.AttributeId == rankId && a.EntityId == personId) == null )
{
DateTime? assessmentDate = row["AssessmentDate"] as DateTime?;
int? giftAttributeId = row["GiftAttributeID"] as int?;
string giftAttributeIdString = Convert.ToString( giftAttributeId );
var definedValueService = new DefinedValueService( lookupContext );
newAttributeValue.IsSystem = false;
newAttributeValue.EntityId = personId;
if ( rank == 1 ) { newAttributeValue.AttributeId = rank1Id; }
if ( rank == 2 ) { newAttributeValue.AttributeId = rank2Id; }
if ( rank == 3 ) { newAttributeValue.AttributeId = rank3Id; }
if ( rank == 4 ) { newAttributeValue.AttributeId = rank4Id; }
newAttributeValue.Value = Convert.ToString( definedValueService.Queryable().Where( a => a.ForeignId == giftAttributeIdString ).FirstOrDefault().Guid );
newAttributeValue.CreatedDateTime = assessmentDate;
newAttributeValueList.Add( newAttributeValue );
completed++;
}
}
if ( newAttributeValueList.Any() )
{
if ( completed % percentage < 1 )
{
int percentComplete = completed / percentage;
ReportProgress( percentComplete, string.Format( "{0:N0} spiritual gifts imported ({1}% complete).", completed, percentComplete ) );
}
else if ( completed % ReportingNumber < 1 )
{
var rockContext = new RockContext();
rockContext.WrapTransaction( () =>
{
rockContext.Configuration.AutoDetectChangesEnabled = false;
rockContext.AttributeValues.AddRange( newAttributeValueList );
rockContext.SaveChanges( DisableAudit );
newAttributeValueList.Clear();
} );
ReportPartialProgress();
}
}
}
if ( newAttributeValueList.Any() )
{
var rockContext = new RockContext();
rockContext.WrapTransaction( () =>
{
rockContext.Configuration.AutoDetectChangesEnabled = false;
rockContext.AttributeValues.AddRange( newAttributeValueList );
rockContext.SaveChanges( DisableAudit );
} );
}
ReportProgress( 100, string.Format( "Finished individual gifts import: {0:N0} spiritual gifts imported.", completed ) );
}