本文整理汇总了C#中FinancialAccountService.FirstOrDefault方法的典型用法代码示例。如果您正苦于以下问题:C# FinancialAccountService.FirstOrDefault方法的具体用法?C# FinancialAccountService.FirstOrDefault怎么用?C# FinancialAccountService.FirstOrDefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FinancialAccountService
的用法示例。
在下文中一共展示了FinancialAccountService.FirstOrDefault方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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 )
{
var lookupContext = new RockContext();
int transactionEntityTypeId = EntityTypeCache.Read( "Rock.Model.FinancialTransaction" ).Id;
var transactionTypeContributionId = DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.TRANSACTION_TYPE_CONTRIBUTION ), lookupContext ).Id;
var currencyTypes = DefinedTypeCache.Read( new Guid( Rock.SystemGuid.DefinedType.FINANCIAL_CURRENCY_TYPE ) );
int currencyTypeACH = currencyTypes.DefinedValues.FirstOrDefault( dv => dv.Guid.Equals( new Guid( Rock.SystemGuid.DefinedValue.CURRENCY_TYPE_ACH ) ) ).Id;
int currencyTypeCash = currencyTypes.DefinedValues.FirstOrDefault( dv => dv.Guid.Equals( new Guid( Rock.SystemGuid.DefinedValue.CURRENCY_TYPE_CASH ) ) ).Id;
int currencyTypeCheck = currencyTypes.DefinedValues.FirstOrDefault( dv => dv.Guid.Equals( new Guid( Rock.SystemGuid.DefinedValue.CURRENCY_TYPE_CHECK ) ) ).Id;
int currencyTypeCreditCard = currencyTypes.DefinedValues.FirstOrDefault( dv => dv.Guid.Equals( new Guid( Rock.SystemGuid.DefinedValue.CURRENCY_TYPE_CREDIT_CARD ) ) ).Id;
int? currencyTypeNonCash = currencyTypes.DefinedValues.Where( dv => dv.Value.Equals( "Non-Cash" ) ).Select( dv => (int?)dv.Id ).FirstOrDefault();
if ( currencyTypeNonCash == null )
{
var newTenderNonCash = new DefinedValue();
newTenderNonCash.Value = "Non-Cash";
newTenderNonCash.Description = "Non-Cash";
newTenderNonCash.DefinedTypeId = currencyTypes.Id;
lookupContext.DefinedValues.Add( newTenderNonCash );
lookupContext.SaveChanges();
currencyTypeNonCash = newTenderNonCash.Id;
}
var creditCardTypes = DefinedTypeCache.Read( new Guid( Rock.SystemGuid.DefinedType.FINANCIAL_CREDIT_CARD_TYPE ) ).DefinedValues;
int sourceTypeOnsite = DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.FINANCIAL_SOURCE_TYPE_ONSITE_COLLECTION ), lookupContext ).Id;
int sourceTypeWebsite = DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.FINANCIAL_SOURCE_TYPE_WEBSITE ), lookupContext ).Id;
int sourceTypeKiosk = DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.FINANCIAL_SOURCE_TYPE_KIOSK ), lookupContext ).Id;
var refundReasons = DefinedTypeCache.Read( new Guid( Rock.SystemGuid.DefinedType.FINANCIAL_TRANSACTION_REFUND_REASON ), lookupContext ).DefinedValues;
var accountList = new FinancialAccountService( lookupContext ).Queryable().AsNoTracking().ToList();
int? defaultBatchId = null;
if ( ImportedBatches.ContainsKey( 0 ) )
{
defaultBatchId = ImportedBatches[0];
}
// Get all imported contributions
var importedContributions = new FinancialTransactionService( lookupContext ).Queryable().AsNoTracking()
.Where( c => c.ForeignId != null )
.ToDictionary( t => (int)t.ForeignId, t => (int?)t.Id );
// 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( "Verifying contribution import ({0:N0} found, {1:N0} already exist).", totalRows, importedContributions.Count ) );
foreach ( var row in tableData.Where( r => r != null ) )
{
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( (int)contributionId ) )
{
var transaction = new FinancialTransaction();
transaction.CreatedByPersonAliasId = ImportPersonAliasId;
transaction.ModifiedByPersonAliasId = ImportPersonAliasId;
transaction.TransactionTypeValueId = transactionTypeContributionId;
transaction.ForeignKey = contributionId.ToString();
transaction.ForeignId = contributionId;
int? giverAliasId = null;
var personKeys = GetPersonKeys( individualId, householdId );
if ( personKeys != null && personKeys.PersonAliasId > 0 )
{
giverAliasId = personKeys.PersonAliasId;
transaction.CreatedByPersonAliasId = giverAliasId;
transaction.AuthorizedPersonAliasId = giverAliasId;
transaction.ProcessedByPersonAliasId = giverAliasId;
}
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.Equals( batchId ) ) )
{
transaction.BatchId = ImportedBatches.FirstOrDefault( b => b.Key.Equals( batchId ) ).Value;
}
else
{
// use the default batch for any non-matching transactions
transaction.BatchId = defaultBatchId;
}
DateTime? receivedDate = row["Received_Date"] as DateTime?;
//.........这里部分代码省略.........
示例2: MapPledge
/// <summary>
/// Maps the pledge.
/// </summary>
/// <param name="queryable">The queryable.</param>
/// <exception cref="System.NotImplementedException"></exception>
private void MapPledge( IQueryable<Row> tableData )
{
var lookupContext = new RockContext();
var accountList = new FinancialAccountService( lookupContext ).Queryable().AsNoTracking().ToList();
var importedPledges = new FinancialPledgeService( lookupContext ).Queryable().AsNoTracking().ToList();
var pledgeFrequencies = DefinedTypeCache.Read( new Guid( Rock.SystemGuid.DefinedType.FINANCIAL_FREQUENCY ), lookupContext ).DefinedValues;
int oneTimePledgeFrequencyId = pledgeFrequencies.FirstOrDefault( f => f.Guid == new Guid( Rock.SystemGuid.DefinedValue.TRANSACTION_FREQUENCY_ONE_TIME ) ).Id;
var newPledges = new List<FinancialPledge>();
int completed = 0;
int totalRows = tableData.Count();
int percentage = ( totalRows - 1 ) / 100 + 1;
ReportProgress( 0, string.Format( "Verifying pledge import ({0:N0} found).", totalRows ) );
foreach ( var row in tableData.Where( r => r != null ) )
{
decimal? amount = row["Total_Pledge"] as decimal?;
DateTime? startDate = row["Start_Date"] as DateTime?;
DateTime? endDate = row["End_Date"] as DateTime?;
if ( amount != null && startDate != null && endDate != null )
{
int? individualId = row["Individual_ID"] as int?;
int? householdId = row["Household_ID"] as int?;
var personKeys = GetPersonKeys( individualId, householdId, includeVisitors: false );
if ( personKeys != null && personKeys.PersonAliasId > 0 )
{
var pledge = new FinancialPledge();
pledge.PersonAliasId = personKeys.PersonAliasId;
pledge.CreatedByPersonAliasId = ImportPersonAliasId;
pledge.ModifiedDateTime = ImportDateTime;
pledge.StartDate = (DateTime)startDate;
pledge.EndDate = (DateTime)endDate;
pledge.TotalAmount = (decimal)amount;
pledge.CreatedDateTime = ImportDateTime;
pledge.ModifiedDateTime = ImportDateTime;
pledge.ModifiedByPersonAliasId = ImportPersonAliasId;
string frequency = row["Pledge_Frequency_Name"].ToString().ToLower();
if ( frequency != null )
{
frequency = frequency.ToLower();
if ( frequency.Equals( "one time" ) || frequency.Equals( "as can" ) )
{
pledge.PledgeFrequencyValueId = oneTimePledgeFrequencyId;
}
else
{
pledge.PledgeFrequencyValueId = pledgeFrequencies
.Where( f => f.Value.ToLower().StartsWith( frequency ) || f.Description.ToLower().StartsWith( frequency ) )
.Select( f => f.Id ).FirstOrDefault();
}
}
string fundName = row["Fund_Name"] as string;
string subFund = row["Sub_Fund_Name"] as string;
if ( fundName != null )
{
var parentAccount = accountList.FirstOrDefault( a => a.Name.Equals( fundName ) && a.CampusId == null );
if ( parentAccount == null )
{
parentAccount = AddAccount( lookupContext, fundName, string.Empty, null, null, null );
accountList.Add( parentAccount );
}
if ( subFund != null )
{
int? campusFundId = null;
// assign a campus if the subfund is a campus fund
var campusFund = CampusList.FirstOrDefault( c => subFund.StartsWith( c.Name ) || subFund.StartsWith( c.ShortCode ) );
if ( campusFund != null )
{
// use full campus name as the subfund
subFund = campusFund.Name;
campusFundId = campusFund.Id;
}
// add info to easily find/assign this fund in the view
subFund = string.Format( "{0} {1}", subFund, fundName );
var childAccount = accountList.FirstOrDefault( c => c.Name.Equals( subFund ) && c.ParentAccountId == parentAccount.Id );
if ( childAccount == null )
{
// create a child account with a campusId if it was set
childAccount = AddAccount( lookupContext, subFund, string.Empty, campusFundId, parentAccount.Id, null );
accountList.Add( childAccount );
}
pledge.AccountId = childAccount.Id;
}
else
{
pledge.AccountId = parentAccount.Id;
//.........这里部分代码省略.........
示例3: BindGiversGrid
//.........这里部分代码省略.........
} ) );
// If a dataview filter was included, find the people who match that criteria
List<int> dataViewPersonIds = null;
var dataViewId = dvpDataView.SelectedValueAsInt();
if ( dataViewId.HasValue )
{
qryTasks.Add( Task.Run( () =>
{
dataViewPersonIds = new List<int>();
var dataView = new DataViewService( _rockContext ).Get( dataViewId.Value );
if ( dataView != null )
{
var errorMessages = new List<string>();
var dvPersonService = new PersonService( _rockContext );
ParameterExpression paramExpression = dvPersonService.ParameterExpression;
Expression whereExpression = dataView.GetExpression( dvPersonService, paramExpression, out errorMessages );
SortProperty sort = null;
var dataViewPersonIdQry = dvPersonService
.Queryable().AsNoTracking()
.Where( paramExpression, whereExpression, sort )
.Select( p => p.Id );
dataViewPersonIds = dataViewPersonIdQry.ToList();
}
} ) );
}
qryTasks.Add( Task.Run( () =>
{
// Clear all the existing grid columns
var selectField = new SelectField();
var oldSelectField = gGiversGifts.ColumnsOfType<SelectField>().FirstOrDefault();
if ( oldSelectField != null )
{
selectField.SelectedKeys.AddRange( oldSelectField.SelectedKeys );
}
gGiversGifts.Columns.Clear();
// Add a column for selecting rows
gGiversGifts.Columns.Add( selectField );
// Add a hidden column for person id
gGiversGifts.Columns.Add(
new RockBoundField
{
DataField = "Id",
HeaderText = "Person Id",
SortExpression = "Id",
Visible = false,
ExcelExportBehavior = ExcelExportBehavior.AlwaysInclude
} );
// Add a column for the person's name
gGiversGifts.Columns.Add(
new RockBoundField
{
DataField = "PersonName",
HeaderText = "Person",
SortExpression = "LastName,NickName"
} );
// add a column for email (but is only included on excel export)
gGiversGifts.Columns.Add(
示例4: BindGiversGrid
/// <summary>
/// Binds the attendees grid.
/// </summary>
private void BindGiversGrid()
{
// Get all the selected criteria values
var dateRange = SlidingDateRangePicker.CalculateDateRangeFromDelimitedValues( drpSlidingDateRange.DelimitedValues );
var start = dateRange.Start;
var end = dateRange.End;
var minAmount = nreAmount.LowerValue;
var maxAmount = nreAmount.UpperValue;
var currencyTypeIds = new List<int>();
cblCurrencyTypes.SelectedValues.ForEach( i => currencyTypeIds.Add( i.AsInteger() ) );
var sourceTypeIds = new List<int>();
cblTransactionSource.SelectedValues.ForEach( i => sourceTypeIds.Add( i.AsInteger() ) );
var accountIds = new List<int>();
foreach ( var cblAccounts in phAccounts.Controls.OfType<RockCheckBoxList>() )
{
accountIds.AddRange( cblAccounts.SelectedValuesAsInt );
}
var dataViewId = dvpDataView.SelectedValueAsInt();
GiversViewBy viewBy = GiversViewBy.Giver;
if ( !HideViewByOption )
{
viewBy = hfViewBy.Value.ConvertToEnumOrNull<GiversViewBy>() ?? GiversViewBy.Giver;
}
// Clear all the existing grid columns
var selectField = new SelectField();
var oldSelectField = gGiversGifts.ColumnsOfType<SelectField>().FirstOrDefault();
if (oldSelectField != null )
{
selectField.SelectedKeys.AddRange( oldSelectField.SelectedKeys );
}
gGiversGifts.Columns.Clear();
// Add a column for selecting rows
gGiversGifts.Columns.Add( selectField );
// Add a column for the person's name
gGiversGifts.Columns.Add(
new RockBoundField
{
DataField = "PersonName",
HeaderText = "Person",
SortExpression = "LastName,NickName"
} );
// add a column for email (but is only included on excel export)
gGiversGifts.Columns.Add(
new RockBoundField
{
DataField = "Email",
HeaderText = "Email",
SortExpression = "Email",
Visible = false,
ExcelExportBehavior = ExcelExportBehavior.AlwaysInclude
} );
// Add a column for total amount
gGiversGifts.Columns.Add(
new CurrencyField
{
DataField = "TotalAmount",
HeaderText = "Total",
SortExpression = "TotalAmount"
} );
// Add columns for the selected account totals
if ( accountIds.Any() )
{
var accounts = new FinancialAccountService( _rockContext )
.Queryable().AsNoTracking()
.Where( a => accountIds.Contains( a.Id ) )
.ToList();
foreach ( int accountId in accountIds )
{
var account = accounts.FirstOrDefault( a => a.Id == accountId );
if ( account != null )
{
gGiversGifts.Columns.Add(
new CurrencyField
{
DataField = account.Id.ToString(),
HeaderText = account.Name,
SortExpression = account.Id.ToString()
} );
}
}
}
// Add a column for the number of gifts
//.........这里部分代码省略.........
示例5: MapPledge
/// <summary>
/// Maps the pledge.
/// </summary>
/// <param name="queryable">The queryable.</param>
/// <exception cref="System.NotImplementedException"></exception>
private void MapPledge( IQueryable<Row> tableData )
{
var lookupContext = new RockContext();
List<FinancialAccount> accountList = new FinancialAccountService( lookupContext ).Queryable().ToList();
List<FinancialPledge> importedPledges = new FinancialPledgeService( lookupContext ).Queryable().ToList();
var pledgeFrequencies = DefinedTypeCache.Read( new Guid( Rock.SystemGuid.DefinedType.FINANCIAL_FREQUENCY ), lookupContext ).DefinedValues;
var newPledges = new List<FinancialPledge>();
int completed = 0;
int totalRows = tableData.Count();
int percentage = ( totalRows - 1 ) / 100 + 1;
ReportProgress( 0, string.Format( "Verifying pledge import ({0:N0} found).", totalRows ) );
foreach ( var row in tableData )
{
decimal? amount = row["Total_Pledge"] as decimal?;
DateTime? startDate = row["Start_Date"] as DateTime?;
DateTime? endDate = row["End_Date"] as DateTime?;
if ( amount != null && startDate != null && endDate != null )
{
int? individualId = row["Individual_ID"] as int?;
int? householdId = row["Household_ID"] as int?;
int? personId = GetPersonAliasId( individualId, householdId );
if ( personId != null && !importedPledges.Any( p => p.PersonAliasId == personId && p.TotalAmount == amount && p.StartDate.Equals( startDate ) ) )
{
var pledge = new FinancialPledge();
pledge.CreatedByPersonAliasId = ImportPersonAlias.Id;
pledge.StartDate = (DateTime)startDate;
pledge.EndDate = (DateTime)endDate;
pledge.TotalAmount = (decimal)amount;
string frequency = row["Pledge_Frequency_Name"].ToString().ToLower();
if ( frequency != null )
{
if ( frequency == "one time" || frequency == "as can" )
{
pledge.PledgeFrequencyValueId = pledgeFrequencies.FirstOrDefault( f => f.Guid == new Guid( Rock.SystemGuid.DefinedValue.TRANSACTION_FREQUENCY_ONE_TIME ) ).Id;
}
else
{
pledge.PledgeFrequencyValueId = pledgeFrequencies
.Where( f => f.Value.ToLower().StartsWith( frequency ) || f.Description.ToLower().StartsWith( frequency ) )
.Select( f => f.Id ).FirstOrDefault();
}
}
string fundName = row["Fund_Name"] as string;
string subFund = row["Sub_Fund_Name"] as string;
if ( fundName != null )
{
FinancialAccount matchingAccount = null;
int? fundCampusId = null;
if ( subFund != null )
{
// match by campus if the subfund appears to be a campus
fundCampusId = CampusList.Where( c => c.Name.StartsWith( subFund ) || c.ShortCode == subFund )
.Select( c => (int?)c.Id ).FirstOrDefault();
if ( fundCampusId != null )
{
matchingAccount = accountList.FirstOrDefault( a => a.Name.StartsWith( fundName ) && a.CampusId != null && a.CampusId.Equals( fundCampusId ) );
}
else
{
matchingAccount = accountList.FirstOrDefault( a => a.Name.StartsWith( fundName ) && a.Name.StartsWith( subFund ) );
}
}
else
{
matchingAccount = accountList.FirstOrDefault( a => a.Name.StartsWith( fundName ) );
}
if ( matchingAccount == null )
{
matchingAccount = AddAccount( lookupContext, fundName, fundCampusId );
accountList.Add( matchingAccount );
}
pledge.AccountId = matchingAccount.Id;
}
// Attributes to add?
// Pledge_Drive_Name
newPledges.Add( pledge );
completed++;
if ( completed % percentage < 1 )
{
int percentComplete = completed / percentage;
ReportProgress( percentComplete, string.Format( "{0:N0} pledges imported ({1}% complete).", completed, percentComplete ) );
}
else if ( completed % ReportingNumber < 1 )
{
//.........这里部分代码省略.........
示例6: 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 )
{
var lookupContext = new RockContext();
int transactionEntityTypeId = EntityTypeCache.Read( "Rock.Model.FinancialTransaction" ).Id;
var transactionTypeContributionId = DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.TRANSACTION_TYPE_CONTRIBUTION ), lookupContext ).Id;
var transactionTypeEventRegistrationId = DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.TRANSACTION_TYPE_EVENT_REGISTRATION ), lookupContext ).Id;
int currencyTypeACH = DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.CURRENCY_TYPE_ACH ), lookupContext ).Id;
int currencyTypeCash = DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.CURRENCY_TYPE_CASH ), lookupContext ).Id;
int currencyTypeCheck = DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.CURRENCY_TYPE_CHECK ), lookupContext ).Id;
int currencyTypeCreditCard = DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.CURRENCY_TYPE_CREDIT_CARD ), lookupContext ).Id;
var refundReasons = DefinedTypeCache.Read( new Guid( Rock.SystemGuid.DefinedType.FINANCIAL_TRANSACTION_REFUND_REASON ), lookupContext ).DefinedValues;
List<FinancialPledge> pledgeList = new FinancialPledgeService( lookupContext ).Queryable().ToList();
List<FinancialAccount> accountList = new FinancialAccountService( lookupContext ).Queryable().ToList();
// Get all imported contributions
var importedContributions = new FinancialTransactionService( lookupContext ).Queryable()
.Select( t => new { ContributionId = t.ForeignId, TransactionId = t.Id } )
.ToDictionary( t => t.ContributionId.AsType<int?>(), t => (int?)t.TransactionId );
var householdAVList = new AttributeValueService( lookupContext ).Queryable().Where( av => av.AttributeId == HouseholdAttributeId ).ToList();
// 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( "Verifying 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();
string fundName = row["Fund_Name"] as string;
//Crossroads - Anything under a fund name that starts with Receipt - is an Event Registration.
if ( fundName.StartsWith( "Receipt -" ) ) { transaction.TransactionTypeValueId = transactionTypeEventRegistrationId; }
else { transaction.TransactionTypeValueId = transactionTypeContributionId; }
int? associatedPersonId;
if ( individualId != null ) { associatedPersonId = GetPersonAliasId( individualId, householdId ); } //will get the exact person if Individual Id is not null.
else { associatedPersonId = GetPersonId( householdAVList, householdId ); } //Will attempt to get the Head first, then Spouse, then Child. Will exclude Other and Visitor
if ( associatedPersonId != null )
{
transaction.AuthorizedPersonAliasId = associatedPersonId;
transaction.CreatedByPersonAliasId = ImportPersonAlias.Id;
transaction.ProcessedByPersonAliasId = associatedPersonId;
transaction.ForeignId = contributionId.ToString();
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"].ToString().ToLower();
if ( contributionType != null )
{
if ( contributionType == "ach" )
{
transaction.CurrencyTypeValueId = currencyTypeACH;
}
else if ( contributionType == "cash" )
{
transaction.CurrencyTypeValueId = currencyTypeCash;
}
else if ( contributionType == "check" )
{
transaction.CurrencyTypeValueId = currencyTypeCheck;
}
else if ( contributionType == "credit card" )
{
//.........这里部分代码省略.........
示例7: MapPledge
/// <summary>
/// Maps the pledge.
/// </summary>
/// <param name="queryable">The queryable.</param>
/// <exception cref="System.NotImplementedException"></exception>
private int MapPledge( CSVInstance csvData )
{
var lookupContext = new RockContext();
var accountList = new FinancialAccountService( lookupContext ).Queryable().AsNoTracking().ToList();
var importedPledges = new FinancialPledgeService( lookupContext ).Queryable().AsNoTracking()
.Where( p => p.ForeignId != null )
.ToDictionary( t => ( int )t.ForeignId, t => ( int? )t.Id );
var pledgeFrequencies = DefinedTypeCache.Read( new Guid( Rock.SystemGuid.DefinedType.FINANCIAL_FREQUENCY ), lookupContext ).DefinedValues;
int oneTimePledgeFrequencyId = pledgeFrequencies.FirstOrDefault( f => f.Guid == new Guid( Rock.SystemGuid.DefinedValue.TRANSACTION_FREQUENCY_ONE_TIME ) ).Id;
var newPledges = new List<FinancialPledge>();
int completed = 0;
ReportProgress( 0, string.Format( "Verifying pledge import ({0:N0} already exist).", importedPledges.Count ) );
string[] row;
// Uses a look-ahead enumerator: this call will move to the next record immediately
while ( (row = csvData.Database.FirstOrDefault()) != null )
{
string amountKey = row[TotalPledge];
decimal? amount = amountKey.AsType<decimal?>();
string startDateKey = row[StartDate];
if ( String.IsNullOrWhiteSpace( startDateKey ) )
{
startDateKey = "01/01/0001";
}
DateTime? startDate = startDateKey.AsType<DateTime?>();
string endDateKey = row[EndDate];
if ( String.IsNullOrWhiteSpace( endDateKey ) )
{
endDateKey = "12/31/9999";
}
DateTime? endDate = endDateKey.AsType<DateTime?>();
string pledgeIdKey = row[PledgeId];
int? pledgeId = pledgeIdKey.AsType<int?>();
if ( amount != null && !importedPledges.ContainsKey( ( int )pledgeId ) )
{
string individualIdKey = row[IndividualID];
int? individualId = individualIdKey.AsType<int?>();
var personKeys = GetPersonKeys( individualId );
if ( personKeys != null && personKeys.PersonAliasId > 0 )
{
var pledge = new FinancialPledge();
pledge.PersonAliasId = personKeys.PersonAliasId;
pledge.CreatedByPersonAliasId = ImportPersonAliasId;
pledge.StartDate = ( DateTime )startDate;
pledge.EndDate = ( DateTime )endDate;
pledge.TotalAmount = ( decimal )amount;
pledge.CreatedDateTime = ImportDateTime;
pledge.ModifiedDateTime = ImportDateTime;
pledge.ModifiedByPersonAliasId = ImportPersonAliasId;
pledge.ForeignKey = pledgeIdKey;
pledge.ForeignId = pledgeId;
string frequency = row[PledgeFrequencyName].ToString().ToLower();
if ( !String.IsNullOrWhiteSpace( frequency ) )
{
frequency = frequency.ToLower();
if ( frequency.Equals( "one time" ) || frequency.Equals( "one-time" ) || frequency.Equals( "as can" ) )
{
pledge.PledgeFrequencyValueId = oneTimePledgeFrequencyId;
}
else
{
pledge.PledgeFrequencyValueId = pledgeFrequencies
.Where( f => f.Value.ToLower().StartsWith( frequency ) || f.Description.ToLower().StartsWith( frequency ) )
.Select( f => f.Id ).FirstOrDefault();
}
}
string fundName = row[FundName] as string;
string subFund = row[SubFundName] as string;
string fundGLAccount = row[FundGLAccount] as string;
string subFundGLAccount = row[SubFundGLAccount] as string;
string isFundActiveKey = row[FundIsActive];
Boolean? isFundActive = isFundActiveKey.AsType<Boolean?>();
string isSubFundActiveKey = row[SubFundIsActive];
Boolean? isSubFundActive = isSubFundActiveKey.AsType<Boolean?>();
if ( !String.IsNullOrWhiteSpace( fundName ) )
{
var parentAccount = accountList.FirstOrDefault( a => a.Name.Equals( fundName.Truncate( 50 ) ) && a.CampusId == null );
if ( parentAccount == null )
{
parentAccount = AddAccount( lookupContext, fundName, string.Empty, null, null, isFundActive );
accountList.Add( parentAccount );
}
if ( !String.IsNullOrWhiteSpace( subFund ) )
{
int? campusFundId = null;
// assign a campus if the subfund is a campus fund
var campusFund = CampusList.FirstOrDefault( c => subFund.StartsWith( c.Name ) || subFund.StartsWith( c.ShortCode ) );
//.........这里部分代码省略.........
示例8: MapContribution
/// <summary>
/// Maps the contribution.
/// </summary>
/// <param name="csvData">The table data.</param>
private int MapContribution( CSVInstance csvData )
{
var lookupContext = new RockContext();
int transactionEntityTypeId = EntityTypeCache.Read( "Rock.Model.FinancialTransaction" ).Id;
var transactionTypeContributionId = DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.TRANSACTION_TYPE_CONTRIBUTION ), lookupContext ).Id;
var currencyTypes = DefinedTypeCache.Read( new Guid( Rock.SystemGuid.DefinedType.FINANCIAL_CURRENCY_TYPE ) );
int currencyTypeACH = currencyTypes.DefinedValues.FirstOrDefault( dv => dv.Guid.Equals( new Guid( Rock.SystemGuid.DefinedValue.CURRENCY_TYPE_ACH ) ) ).Id;
int currencyTypeCash = currencyTypes.DefinedValues.FirstOrDefault( dv => dv.Guid.Equals( new Guid( Rock.SystemGuid.DefinedValue.CURRENCY_TYPE_CASH ) ) ).Id;
int currencyTypeCheck = currencyTypes.DefinedValues.FirstOrDefault( dv => dv.Guid.Equals( new Guid( Rock.SystemGuid.DefinedValue.CURRENCY_TYPE_CHECK ) ) ).Id;
int currencyTypeCreditCard = currencyTypes.DefinedValues.FirstOrDefault( dv => dv.Guid.Equals( new Guid( Rock.SystemGuid.DefinedValue.CURRENCY_TYPE_CREDIT_CARD ) ) ).Id;
int? currencyTypeNonCash = currencyTypes.DefinedValues.Where( dv => dv.Value.Equals( "Non-Cash" ) ).Select( dv => ( int? )dv.Id ).FirstOrDefault();
if ( currencyTypeNonCash == null )
{
var newTenderNonCash = new DefinedValue();
newTenderNonCash.Value = "Non-Cash";
newTenderNonCash.Description = "Non-Cash";
newTenderNonCash.DefinedTypeId = currencyTypes.Id;
lookupContext.DefinedValues.Add( newTenderNonCash );
lookupContext.SaveChanges();
currencyTypeNonCash = newTenderNonCash.Id;
}
var creditCardTypes = DefinedTypeCache.Read( new Guid( Rock.SystemGuid.DefinedType.FINANCIAL_CREDIT_CARD_TYPE ) ).DefinedValues;
int sourceTypeOnsite = DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.FINANCIAL_SOURCE_TYPE_ONSITE_COLLECTION ), lookupContext ).Id;
int sourceTypeWebsite = DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.FINANCIAL_SOURCE_TYPE_WEBSITE ), lookupContext ).Id;
int sourceTypeKiosk = DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.FINANCIAL_SOURCE_TYPE_KIOSK ), lookupContext ).Id;
var refundReasons = DefinedTypeCache.Read( new Guid( Rock.SystemGuid.DefinedType.FINANCIAL_TRANSACTION_REFUND_REASON ), lookupContext ).DefinedValues;
var accountList = new FinancialAccountService( lookupContext ).Queryable().AsNoTracking().ToList();
int? defaultBatchId = null;
if ( ImportedBatches.ContainsKey( 0 ) )
{
defaultBatchId = ImportedBatches[0];
}
// Get all imported contributions
var importedContributions = new FinancialTransactionService( lookupContext ).Queryable().AsNoTracking()
.Where( c => c.ForeignId != null )
.ToDictionary( t => ( int )t.ForeignId, t => ( int? )t.Id );
// List for batching new contributions
var newTransactions = new List<FinancialTransaction>();
int completed = 0;
ReportProgress( 0, string.Format( "Verifying contribution import ({0:N0} already exist).", importedContributions.Count ) );
string[] row;
// Uses a look-ahead enumerator: this call will move to the next record immediately
while ( (row = csvData.Database.FirstOrDefault()) != null )
{
string individualIdKey = row[IndividualID];
int? individualId = individualIdKey.AsType<int?>();
string contributionIdKey = row[ContributionID];
int? contributionId = contributionIdKey.AsType<int?>();
if ( contributionId != null && !importedContributions.ContainsKey( ( int )contributionId ) )
{
var transaction = new FinancialTransaction();
transaction.CreatedByPersonAliasId = ImportPersonAliasId;
transaction.ModifiedByPersonAliasId = ImportPersonAliasId;
transaction.TransactionTypeValueId = transactionTypeContributionId;
transaction.ForeignKey = contributionId.ToString();
transaction.ForeignId = contributionId;
int? giverAliasId = null;
var personKeys = GetPersonKeys( individualId );
if ( personKeys != null && personKeys.PersonAliasId > 0 )
{
giverAliasId = personKeys.PersonAliasId;
transaction.CreatedByPersonAliasId = giverAliasId;
transaction.AuthorizedPersonAliasId = giverAliasId;
transaction.ProcessedByPersonAliasId = giverAliasId;
}
else if ( AnonymousGiverAliasId != null && AnonymousGiverAliasId > 0 )
{
giverAliasId = AnonymousGiverAliasId;
transaction.AuthorizedPersonAliasId = giverAliasId;
transaction.ProcessedByPersonAliasId = giverAliasId;
}
string summary = row[Memo] as string;
if ( !String.IsNullOrWhiteSpace( summary ) )
{
transaction.Summary = summary;
}
string batchIdKey = row[ContributionBatchID];
int? batchId = batchIdKey.AsType<int?>();
if ( batchId != null && ImportedBatches.Any( b => b.Key.Equals( batchId ) ) )
{
transaction.BatchId = ImportedBatches.FirstOrDefault( b => b.Key.Equals( batchId ) ).Value;
}
//.........这里部分代码省略.........
示例9: 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 )
{
var lookupContext = new RockContext();
int transactionEntityTypeId = EntityTypeCache.Read( "Rock.Model.FinancialTransaction" ).Id;
var transactionTypeContributionId = DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.TRANSACTION_TYPE_CONTRIBUTION ), lookupContext ).Id;
int currencyTypeACH = DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.CURRENCY_TYPE_ACH ), lookupContext ).Id;
int currencyTypeCash = DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.CURRENCY_TYPE_CASH ), lookupContext ).Id;
int currencyTypeCheck = DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.CURRENCY_TYPE_CHECK ), lookupContext ).Id;
int currencyTypeCreditCard = DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.CURRENCY_TYPE_CREDIT_CARD ), lookupContext ).Id;
var refundReasons = DefinedTypeCache.Read( new Guid( Rock.SystemGuid.DefinedType.FINANCIAL_TRANSACTION_REFUND_REASON ), lookupContext ).DefinedValues;
var accountList = new FinancialAccountService( lookupContext ).Queryable().ToList();
// Get all imported contributions
var importedContributions = new FinancialTransactionService( lookupContext ).Queryable()
.Where( c => c.ForeignId != null )
.ToDictionary( t => t.ForeignId.AsType<int>(), t => (int?)t.Id );
// 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( "Verifying contribution import ({0:N0} found, {1:N0} already exist).", totalRows, importedContributions.Count ) );
foreach ( var row in tableData.Where( r => r != null ) )
{
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( (int)contributionId ) )
{
var transaction = new FinancialTransaction();
transaction.CreatedByPersonAliasId = ImportPersonAlias.Id;
transaction.TransactionTypeValueId = transactionTypeContributionId;
transaction.ForeignId = contributionId.ToString();
var personKeys = GetPersonKeys( individualId, householdId, includeVisitors: false );
if ( personKeys != null )
{
transaction.AuthorizedPersonAliasId = personKeys.PersonAliasId;
transaction.ProcessedByPersonAliasId = personKeys.PersonAliasId;
}
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.Equals( batchId ) ) )
{
transaction.BatchId = ImportedBatches.FirstOrDefault( b => b.Key.Equals( 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"].ToString().ToLower();
if ( contributionType != null )
{
if ( contributionType == "ach" )
{
transaction.CurrencyTypeValueId = currencyTypeACH;
}
else if ( contributionType == "cash" )
{
transaction.CurrencyTypeValueId = currencyTypeCash;
}
else if ( contributionType == "check" )
{
transaction.CurrencyTypeValueId = currencyTypeCheck;
}
else if ( contributionType == "credit card" )
{
transaction.CurrencyTypeValueId = currencyTypeCreditCard;
}
else
{
isTypeNonCash = true;
}
}
string checkNumber = row["Check_Number"] as string;
if ( checkNumber != null && checkNumber.AsType<int?>() != null )
{
//.........这里部分代码省略.........