/// <summary>
/// Formats the selection.
/// </summary>
/// <param name="entityType">Type of the entity.</param>
/// <param name="selection">The selection.</param>
/// <returns></returns>
public override string FormatSelection( Type entityType, string selection )
{
string result = "Giving Amount";
string[] selectionValues = selection.Split( '|' );
if ( selectionValues.Length >= 4 )
{
ComparisonType comparisonType = selectionValues[0].ConvertToEnum<ComparisonType>( ComparisonType.GreaterThanOrEqualTo );
decimal amount = selectionValues[1].AsDecimalOrNull() ?? 0.00M;
string accountNames = string.Empty;
if ( selectionValues.Length >= 5 )
{
var accountGuids = selectionValues[4].Split( ',' ).Select( a => a.AsGuid() ).ToList();
accountNames = new FinancialAccountService( new RockContext() ).GetByGuids( accountGuids ).Select( a => a.Name ).ToList().AsDelimited( "," );
}
bool combineGiving = false;
if ( selectionValues.Length >= 6 )
{
combineGiving = selectionValues[5].AsBooleanOrNull() ?? false;
}
SlidingDateRangePicker fakeSlidingDateRangePicker = new SlidingDateRangePicker();
if ( selectionValues.Length >= 7 )
{
// convert comma delimited to pipe
fakeSlidingDateRangePicker.DelimitedValues = selectionValues[6].Replace( ',', '|' );
}
else
{
// if converting from a previous version of the selection
var lowerValue = selectionValues[2].AsDateTime();
var upperValue = selectionValues[3].AsDateTime();
fakeSlidingDateRangePicker.SlidingDateRangeMode = SlidingDateRangePicker.SlidingDateRangeType.DateRange;
fakeSlidingDateRangePicker.SetDateRangeModeValue( new DateRange( lowerValue, upperValue ) );
}
result = string.Format(
"{4}Giving amount total {0} {1} {2}. Date Range: {3}",
comparisonType.ConvertToString().ToLower(),
amount.ToString( "C" ),
!string.IsNullOrWhiteSpace( accountNames ) ? " to accounts:" + accountNames : string.Empty,
SlidingDateRangePicker.FormatDelimitedValues( fakeSlidingDateRangePicker.DelimitedValues ),
combineGiving ? "Combined " : string.Empty);
}
return result;
}