コード例 #1
0
        public IEnumerable <ControlTotalResult> GetControlTotals(System.Web.Http.OData.Query.ODataQueryOptions <FinancialBatch> queryOptions = null)
        {
            var financialBatchQuery = new FinancialBatchService(this.Service.Context as Rock.Data.RockContext).Queryable();

            financialBatchQuery = queryOptions.ApplyTo(financialBatchQuery) as IOrderedQueryable <FinancialBatch>;

            var batchControlTotalsQuery = financialBatchQuery.SelectMany(a => a.Transactions).Where(a => a.BatchId.HasValue).GroupBy(a => a.BatchId.Value).Select(a => new
            {
                BatchId = a.Key,
                TransactionTotalAmounts = a.Select(x => x.TransactionDetails.Sum(d => (decimal?)d.Amount))
            });

            var batchControlTotalsList = batchControlTotalsQuery.ToList();

            var controlTotalsList = batchControlTotalsList.Select(a => new ControlTotalResult
            {
                FinancialBatchId   = a.BatchId,
                ControlTotalCount  = a.TransactionTotalAmounts.Count(),
                ControlTotalAmount = a.TransactionTotalAmounts.Sum(x => (decimal?)x) ?? 0
            }).ToList();

            return(controlTotalsList);
        }