public ActionResult IncreaseAccountBalance(Guid account_id, decimal amount)
        {
            if (amount <= 0)
            {
                throw new AmountException("Amount less than zero or equals");
            }

            if (!_accountRepository.AccountExists(account_id))
            {
                throw new NotFoundException("No account with this id");
            }


            // creating our dto object for new transaction
            var accountHistoryForCreate = new AccountHistoryForCreationDto()
            {
                AccountId = account_id,
                Amount    = amount,
                ChangedAt = DateTime.UtcNow,
                Operation = Operation.Increase
            };

            var accountHistoryToReturn = AccountUpdateByTransaction(accountHistoryForCreate);

            return(Ok(new { status = "ok", result = new { balance = accountHistoryToReturn.Balance } }));
        }
        private AccountDto AccountUpdateByTransaction(AccountHistoryForCreationDto accountHistoryForCreation)
        {
            var accountHistoryEntity = _mapper.Map <Entities.AccountHistory>(accountHistoryForCreation);

            _accountRepository.AddAccountHistory(accountHistoryForCreation.AccountId, accountHistoryEntity);
            _accountRepository.Save();


            // update balance on our account
            var accountFromRepo = _accountRepository.UpdateAccountBalance(accountHistoryForCreation.AccountId);

            _accountRepository.Save();

            // If some changes with ApI design,  we could return normal object rather than single value
            return(_mapper.Map <AccountDto>(accountFromRepo));
        }
        public ActionResult TranferAccountBalance(Guid source_account_id, Guid destination_account_id, decimal amount)
        {
            if (amount <= 0)
            {
                throw new AmountException("Amount less than zero or equals");
            }
            if (!_accountRepository.AccountExists(source_account_id))
            {
                throw new NotFoundException("No source_account with this id");
            }
            if (!_accountRepository.AccountExists(destination_account_id))
            {
                throw new NotFoundException("No destination_account with this id");
            }

            // creating our source dto object
            var sourceAccountHistoryForCreate = new AccountHistoryForCreationDto()
            {
                AccountId = source_account_id,
                Amount    = amount,
                ChangedAt = DateTime.UtcNow,
                Operation = Operation.Decrease
            };

            // creating our destination dto object for new transaction
            var destinationAccountHistoryForCreate = new AccountHistoryForCreationDto()
            {
                AccountId = destination_account_id,
                Amount    = amount,
                ChangedAt = DateTime.UtcNow,
                Operation = Operation.Increase
            };

            var sourceAccountHistoryToReturn      = AccountUpdateByTransaction(sourceAccountHistoryForCreate);
            var destinationAccountHistoryToReturn = AccountUpdateByTransaction(destinationAccountHistoryForCreate);

            return(Ok(new { status = "ok", result =
                                new { source_balance = sourceAccountHistoryToReturn.Balance,
                                      destination_balance = destinationAccountHistoryToReturn.Balance } }));
        }