예제 #1
0
        // TODO: change name, this service categorizes all the transactions of a month with similar origins
        public async Task CategorizeAllTransactionsWithSimilarOrigins(CategorizeUserTransactionsDTO dto)
        {
            var transactionToUpdate = await _transactionRepository.GetById(dto.TransactionId);

            Validate.NotNull(transactionToUpdate, "This Transaction doesn't exist");

            var bankAccount = await _bankAccountRepository.GetById(transactionToUpdate.BankAccountId);

            Validate.NotNull(bankAccount, "Access Denied");

            Validate.IsTrue(bankAccount.UserId == dto.UserId, "Access Denied");

            _transactionRepository.Update(transactionToUpdate);

            await UpdateAllTransactionsWithSimilarOriginsByMonth(transactionToUpdate, dto.CategoryId);

            Validate.IsTrue(await _uow.CommitAsync(), "Ocorreu um problema na criação da transação");

            var message = transactionToUpdate.Id.ToString();

            _queueMessageService.SendMessage(message); // TODO: use a valid key (and try to use UserSecrets), this is using a invalid key from appsettings.json
            // TODO: _bus.RaiseEvent(new UserTransactionsWereCategorizedEvent(dto))
        }
예제 #2
0
        public async Task <IActionResult> CategorizeAllTransactionsWithSimilarOrigins([FromBody] CategorizeUserTransactionsDTO dto)
        {
            dto.UserId = GetLoggedUserId();
            await _transactionService.CategorizeAllTransactionsWithSimilarOrigins(dto);

            return(Ok());
        }