示例#1
0
        private void the_wallet_history_does_not_include_the_transaction()
        {
            WalletHistoryModel  walletHistory  = this.GetWalletHistory(this.proofOfStakeSteps.PremineNodeWithCoins, this.proofOfStakeSteps.PremineWallet);
            AccountHistoryModel accountHistory = walletHistory.AccountsHistoryModel.FirstOrDefault();

            accountHistory?.TransactionsHistory?.Where(txn => txn.Type == TransactionItemType.Send).Count().Should().Be(0);
        }
示例#2
0
 public AccountHistoryDto MapAccountHistoryModel(AccountHistoryModel entry)
 {
     return(_mapper.Map <AccountHistoryDto>(entry));
 }
 public async Task AddEntry(AccountHistoryModel entry) => await _context.AccountHistory.AddAsync(entry);
 public void DeleteAccountEntry(AccountHistoryModel accountEntry) => _context.Remove(accountEntry);
        /// <summary>
        /// Добавление записи об изменении счета
        /// </summary>
        /// <param name="account">DTO счета</param>
        /// <param name="operationId">Id операции</param>
        /// <param name="amount">Сумма изменения по счету</param>
        /// <param name="isTopUp">Проверка действмя</param>
        /// <param name="dueDate">Дата влияния на счет</param>
        /// <param name="description">Описание</param>
        /// <param name="accountPresent">Нужно ли создавать счет</param>
        /// <returns></returns>
        public async Task <ResponseBaseDto> FormAccountEntryResponse(AccountDto account,
                                                                     Guid operationId,
                                                                     decimal amount,
                                                                     bool isTopUp,
                                                                     DateTimeOffset dueDate,
                                                                     string description,
                                                                     bool accountPresent)
        {
            var helperListForAccounts = new List <AccountModel>();
            var initialBalance        = account.Balance;
            var balance = new decimal();
            AccountHistoryModel entry;

            if (isTopUp)
            {
                balance = _helper.TopUpBalance(initialBalance, amount);
            }
            else
            {
                if (_helper.ValidateAmmount(initialBalance, amount))
                {
                    return(_helper.FormMessageResponse(_errorStatus, _message));
                }
                else
                {
                    balance = _helper.WithDrawlBalance(initialBalance, amount);
                }
            }


            if (accountPresent)
            {
                helperListForAccounts.Add(_helper.entryForUpdate(account, balance));
            }
            else
            {
                account.Id = await _helper.SaveAccount(account, balance);
            }
            if (isTopUp)
            {
                entry = new AccountHistoryModel(Guid.Empty, account.Id, amount, balance, dueDate, operationId, description);
            }
            else
            {
                entry = new AccountHistoryModel(account.Id, amount, balance, dueDate, description, operationId);
            }
            await _accountsHistoryRepository.AddEntry(entry);

            if (helperListForAccounts.Count != 0)
            {
                _accountRepository.Update(helperListForAccounts);
            }
            if (await _accountsHistoryRepository.SaveChangesAsync() == 0)
            {
                throw new ApplicationException();
            }


            var result = new AccountTransferDto
            {
                AccountId      = account.Id,
                CurrentBalance = balance
            };

            return(_helper.FormResponseForCreateEntrySolo(result));
        }
        /// <summary>
        /// Добавление записи об изменении счета
        /// </summary>
        /// <param name="sourceAccount">DTO счета с которого совершается проводка</param>
        /// <param name="destinationAccount">DTO счета с на который совершается проводка</param>
        /// <param name="operationId">Id операции</param>
        /// <param name="amount">Сумма проводки </param>
        /// <param name="dueDate">Дата влия ния на проводку</param>
        /// <param name="description">Описание проводки</param>
        /// <param name="isSourcePresent">Присутствует ли счет с которго совершается проводка</param>
        /// <param name="isDestinationPresent">Присутсвует ли счет на который совершается проводка</param>
        /// <returns></returns>
        public async Task <ResponseBaseDto> FormAccountEntryResponse(AccountDto sourceAccount,
                                                                     AccountDto destinationAccount,
                                                                     Guid operationId,
                                                                     decimal amount,
                                                                     DateTimeOffset dueDate,
                                                                     string description,
                                                                     bool isSourcePresent,
                                                                     bool isDestinationPresent)
        {
            var emptyAccount              = "00000000000000000000";
            var initialSourceBalance      = sourceAccount.Balance;
            var initialDestinationBalance = destinationAccount.Balance;
            var sourceBalance             = new decimal();
            var destinationBalance        = new decimal();
            var helperListForUpdates      = new List <AccountModel>();

            if (sourceAccount.AccountNumber != emptyAccount && sourceAccount.IsActive == false)
            {
                if (_helper.ValidateAmmount(initialSourceBalance, amount))
                {
                    return(_helper.FormMessageResponse(_errorStatus, _message));
                }
                else
                {
                    sourceBalance = _helper.WithDrawlBalance(initialSourceBalance, amount);
                }

                if (isSourcePresent)
                {
                    helperListForUpdates.Add(_helper.entryForUpdate(sourceAccount, sourceBalance));
                }
                else
                {
                    sourceAccount.Id = await _helper.SaveAccount(sourceAccount, sourceBalance);
                }
            }
            else if (sourceAccount.AccountNumber != emptyAccount && sourceAccount.IsActive == true)
            {
                sourceBalance = _helper.TopUpBalance(initialSourceBalance, amount);
                if (isSourcePresent)
                {
                    helperListForUpdates.Add(_helper.entryForUpdate(sourceAccount, sourceBalance));
                }
                else
                {
                    sourceAccount.Id = await _helper.SaveAccount(sourceAccount, sourceBalance);
                }
            }


            if (destinationAccount.AccountNumber != emptyAccount && destinationAccount.IsActive == true)
            {
                if (_helper.ValidateAmmount(initialDestinationBalance, amount))
                {
                    return(_helper.FormMessageResponse(_errorStatus, _message));
                }
                else
                {
                    destinationBalance = _helper.WithDrawlBalance(initialDestinationBalance, amount);
                }

                if (isDestinationPresent)
                {
                    helperListForUpdates.Add(_helper.entryForUpdate(destinationAccount, destinationBalance));
                }
                else
                {
                    destinationAccount.Id = await _helper.SaveAccount(destinationAccount, destinationBalance);
                }
            }
            else if (destinationAccount.AccountNumber != emptyAccount && destinationAccount.IsActive == false)
            {
                destinationBalance = _helper.TopUpBalance(initialDestinationBalance, amount);
                if (isDestinationPresent)
                {
                    helperListForUpdates.Add(_helper.entryForUpdate(destinationAccount, destinationBalance));
                }
                else
                {
                    destinationAccount.Id = await _helper.SaveAccount(destinationAccount, destinationBalance);
                }
            }

            var entry = new AccountHistoryModel(destinationAccount.Id, sourceAccount.Id, amount, sourceBalance, destinationBalance, dueDate, description, operationId);
            await _accountsHistoryRepository.AddEntry(entry);

            if (helperListForUpdates.Count != 0)
            {
                _helper.UpdateAccount(helperListForUpdates);
            }
            if (await _accountsHistoryRepository.SaveChangesAsync() == 0)
            {
                throw new ApplicationException();
            }


            var result = new TransactionDto
            {
                DestinationAccountId = destinationAccount.Id,
                SourceAccountId      = sourceAccount.Id,
            };

            return(_helper.FormResponseForCreateEntryTransaction(result));
        }