Beispiel #1
0
 public async Task Process(RetrieveBudgetPlannersRequest request, RetrieveBudgetPlannersResponse response, CancellationToken cancellationToken)
 {
     foreach (var budget in response.Result)
     {
         budget.Balance = await _transactionProvider.GetBalance(budget.Id, cancellationToken);
     }
 }
        public async Task Process(RetrieveBudgetPlannerRequest request, RetrieveBudgetPlannerResponse response, CancellationToken cancellationToken)
        {
            if (!Response.IsSuccessful(response))
            {
                return;
            }

            response.Amount = await _transactionProvider.GetBalance(response.Result.Id, cancellationToken);

            response.IsSuccessful = true;
        }
        public async Task <CreateTransactionResponse> Handle(CreateTransactionRequest request, CancellationToken cancellationToken)
        {
            var transaction = _mapperProvider.Map <CreateTransactionRequest, Transaction>(request);

            var budgetPlanner = await _budgetPlannerService.GetBudgetPlanner(transaction.BudgetId, cancellationToken);

            budgetPlanner.LastUpdated = SqlDateTime.MinValue.Value;

            var previousBalance = await _transactionProvider.GetBalance(transaction.BudgetId, cancellationToken, true);

            if (transaction.Id != default)
            {
                transaction = await _transactionService.SaveTransaction(transaction, cancellationToken);

                return(Response.Success <CreateTransactionResponse>(transaction));
            }

            transaction = await _transactionService.SaveTransaction(transaction, cancellationToken, false);

            var transactionLedger = new TransactionLedger
            {
                Transaction = transaction,
                Amount      = transaction.Type == Domains.Enumerations.TransactionType.Expense
                    ? -transaction.Amount
                    : transaction.Amount,
                PreviousBalance = previousBalance,
                NewBalance      = transaction.Type == Domains.Enumerations.TransactionType.Expense
                    ? previousBalance - transaction.Amount
                    : previousBalance + transaction.Amount
            };

            await _transactionLedgerService
            .SaveTransactionLedger(transactionLedger, true, cancellationToken);

            return(Response.Success <CreateTransactionResponse>(transaction));
        }