本文整理汇总了C#中FinancialAccountService.Add方法的典型用法代码示例。如果您正苦于以下问题:C# FinancialAccountService.Add方法的具体用法?C# FinancialAccountService.Add怎么用?C# FinancialAccountService.Add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FinancialAccountService
的用法示例。
在下文中一共展示了FinancialAccountService.Add方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
//.........这里部分代码省略.........
示例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 accountService = new FinancialAccountService();
List<FinancialAccount> importedAccounts = accountService.Queryable().ToList();
List<DefinedValue> pledgeFrequencies = new DefinedValueService().GetByDefinedTypeGuid( new Guid( Rock.SystemGuid.DefinedType.FINANCIAL_FREQUENCY ) ).ToList();
List<FinancialPledge> importedPledges = new FinancialPledgeService().Queryable().ToList();
var newPledges = new List<FinancialPledge>();
int completed = 0;
int totalRows = tableData.Count();
int percentage = ( totalRows - 1 ) / 100 + 1;
ReportProgress( 0, string.Format( "Checking 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 = GetPersonId( individualId, householdId );
if ( personId != null && !importedPledges.Any( p => p.PersonId == 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"] as string;
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.Name.StartsWith( frequency ) || f.Description.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 = importedAccounts.FirstOrDefault( a => a.Name.StartsWith( fundName ) && a.CampusId != null && a.CampusId.Equals( fundCampusId ) );
}
else
{
matchingAccount = importedAccounts.FirstOrDefault( a => a.Name.StartsWith( fundName ) && a.Name.StartsWith( subFund ) );
}
}
else
{
matchingAccount = importedAccounts.FirstOrDefault( a => a.Name.StartsWith( fundName ) );
}
if ( matchingAccount == null )
{
matchingAccount = new FinancialAccount();
matchingAccount.Name = fundName;
matchingAccount.PublicName = fundName;
matchingAccount.IsTaxDeductible = true;
matchingAccount.IsActive = true;
matchingAccount.CampusId = fundCampusId;
matchingAccount.CreatedByPersonAliasId = ImportPersonAlias.Id;
accountService.Add( matchingAccount );
accountService.Save( matchingAccount );
importedAccounts.Add( matchingAccount );
pledge.AccountId = matchingAccount.Id;
}
}
// Attributes to add?
// Pledge_Drive_Name
//.........这里部分代码省略.........
示例3: 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?;
//.........这里部分代码省略.........
示例4: 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" )
{
//.........这里部分代码省略.........
示例5: MapContribution
//.........这里部分代码省略.........
FinancialAccount matchingAccount = null;
int? parentAccountId = null;
string parentAccountName = String.Empty;
int? fundCampusId = null;
fundName = fundName.Trim();
string subFund = row["Sub_Fund_Name"] as string;
if ( subFund != null )
{
subFund = subFund.Trim();
// Check if subfund was used to mark a multi-site campus
fundCampusId = CampusList.Where( c => subFund.StartsWith( c.Name ) || subFund.StartsWith( c.ShortCode ) )
.Select( c => (int?)c.Id ).FirstOrDefault();
// Matched a campus, check to see if an account exists for that campus already
if ( fundCampusId != null )
{
matchingAccount = accountList.FirstOrDefault( a => a.Name.Equals( fundName )
&& a.CampusId != null && a.CampusId.Equals( fundCampusId ) );
}
else
{
// No campus match, look for an account that matches parent name and subfund name
matchingAccount = accountList.FirstOrDefault( a => a.ParentAccountId != null && a.ParentAccount.Name.Equals( fundName ) && a.Name.Equals( subFund ) );
if ( matchingAccount == null )
{
// Check if a parent account exists already
FinancialAccount parentAccount = accountList.FirstOrDefault( a => a.Name.Equals( fundName ) );
if ( parentAccount == null )
{
parentAccount = AddAccount( lookupContext, fundName, fundCampusId );
accountList.Add( parentAccount );
}
// set data for subfund to be created
parentAccountId = parentAccount.Id;
fundName = subFund;
parentAccountName = parentAccount.Name;
}
}
}
else
{
matchingAccount = accountList.FirstOrDefault( a => a.Name.Equals( fundName ) && a.CampusId == null );
}
if ( matchingAccount == null )
{
// No account matches, create the new account with campus Id and parent Id if they were set
matchingAccount = AddAccount( lookupContext, fundName, fundCampusId, parentAccountName, parentAccountId );
accountList.Add( matchingAccount );
}
var transactionDetail = new FinancialTransactionDetail();
transactionDetail.Amount = (decimal)amount;
transactionDetail.CreatedDateTime = receivedDate;
transactionDetail.AccountId = matchingAccount.Id;
transactionDetail.IsNonCash = isTypeNonCash;
transaction.TransactionDetails.Add( transactionDetail );
if ( amount < 0 )
示例6: 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 ) );
//.........这里部分代码省略.........
示例7: 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;
}
//.........这里部分代码省略.........
示例8: MapContribution
//.........这里部分代码省略.........
{
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 )
{
// set the transaction code to the check number
transaction.TransactionCode = checkNumber;
}
string fundName = row["Fund_Name"] as string;
string subFund = row["Sub_Fund_Name"] as string;
decimal? amount = row["Amount"] as decimal?;
if ( fundName != null & amount != null )
{
int transactionAccountId;
var parentAccount = accountList.FirstOrDefault( a => a.Name.Equals( fundName ) && a.CampusId == null );
if ( parentAccount == null )
{
parentAccount = AddAccount( lookupContext, fundName, 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, campusFundId, parentAccount.Id );
accountList.Add( childAccount );
}
transactionAccountId = childAccount.Id;
}
else
{
transactionAccountId = parentAccount.Id;
}