コード例 #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);
        }
コード例 #2
0
        private async Task <ICommandResult> Add(SubsidiaryBatchExpenseEditorForm editor)
        {
            var batch = await CreateBatch(editor);

            await CreateTransactions(editor, batch);

            return(new SuccessResult(batch.Id));
        }
コード例 #3
0
        private IEnumerable <Account> GetAccounts(SubsidiaryBatchExpenseEditorForm editor)
        {
            var ids = editor.Transactions
                      .Select(t => t.AccountId)
                      .ToArray();

            return(accounts.All()
                   .Where(a => ids.Contains(a.Id))
                   .ToArray());
        }
コード例 #4
0
        private Task CreateTransactions(SubsidiaryBatchExpenseEditorForm editor, ExpenseBatch batch)
        {
            var batchAccounts = GetAccounts(editor);

            editor.Transactions
            .Select(t => t.BuildExpense(batch, context))
            .ForEach(t =>
            {
                batchAccounts.First(x => x.Id == t.AccountId)
                .AddExpense(t);
            });

            return(context.SaveChangesAsync());
        }