/// <summary> /// Binds the payments grid. /// </summary> private void BindPaymentsGrid() { if ( Registration != null ) { using ( var rockContext = new RockContext() ) { var currencyTypes = new Dictionary<int, string>(); var creditCardTypes = new Dictionary<int, string>(); int registrationEntityTypeId = EntityTypeCache.Read( typeof( Rock.Model.Registration ) ).Id; // Get all the transactions related to this registration var qry = new FinancialTransactionService( rockContext ) .Queryable().AsNoTracking() .Where( t => t.TransactionDateTime.HasValue && t.TransactionDetails .Any( d => d.EntityTypeId.HasValue && d.EntityTypeId.Value == registrationEntityTypeId && d.EntityId.HasValue && d.EntityId.Value == Registration.Id ) ); SortProperty sortProperty = gPayments.SortProperty; if ( sortProperty != null ) { if ( sortProperty.Property == "TotalAmount" ) { if ( sortProperty.Direction == SortDirection.Ascending ) { qry = qry.OrderBy( t => t.TransactionDetails.Sum( d => (decimal?)d.Amount ) ?? 0.00M ); } else { qry = qry.OrderByDescending( t => t.TransactionDetails.Sum( d => (decimal?)d.Amount ) ?? 0.0M ); } } else { qry = qry.Sort( sortProperty ); } } else { qry = qry.OrderByDescending( t => t.TransactionDateTime ).ThenByDescending( t => t.Id ); } gPayments.DataSource = qry.ToList().Select( p => new { p.Id, TransactionDateTime = p.TransactionDateTime.Value.ToShortDateString() + "<br/>" + p.TransactionDateTime.Value.ToShortTimeString(), Details = FormatDetails( p ), p.TotalAmount }); gPayments.DataBind(); } } }