Beispiel #1
0
        private async Task <BatchExpenseEditorForm> GetForBatch(int batchId)
        {
            var expenseTypes = GetExpenseTypes();
            var batch        = await batches.GetById(batchId)
                               .Where(b => !b.Committed)
                               .Include(b => b.Fund)
                               .Include(b => b.Payee)
                               .Include(b => b.TransactionSubType)
                               .AsNoTracking()
                               .FirstOrDefaultAsync();

            if (batch == null)
            {
                return(null);
            }

            var transactions = await expenses.All()
                               .Include(e => e.ExpenseCategory)
                               .Include(e => e.Account)
                               .Where(e => e.TransactionBatchId == batch.Id)
                               .AsNoTracking()
                               .ToArrayAsync();

            if (batch.Fund is SubsidiaryFund)
            {
                return(SubsidiaryBatchExpenseEditorForm.FromBatch(batch, transactions, expenseTypes));
            }

            if (batch.Fund is ClientFund)
            {
                return(ClientBatchExpenseEditorForm.FromBatch(batch, transactions, expenseTypes));
            }

            return(null);
        }