private void AddClientCashFlow(InnerTransactionUpdateDto dto, MoneyAction moneyAction) { var clientCashFlow = new ClientCashFlow() { ClientId = dto.AgentId, CoinId = dto.CoinId, Amount = dto.Amount, Matched = false, MoenyAction = moneyAction }; _unitOfWork.GenericRepository <ClientCashFlow>().Insert(clientCashFlow); }
private void AgentBalnaceArbitrage(InnerTransactionInsertDto dto, MoneyAction moneyAction) { var clientCash = _unitOfWork.GenericRepository <ClientCash>() .FindBy(c => c.CoinId == dto.CoinId && c.ClientId == dto.AgentId) .FirstOrDefault(); clientCash.Total += dto.Amount; clientCash.Total += dto.AgentCommission; clientCash.ModifiedBy = _appSession.GetUserName(); _unitOfWork.GenericRepository <ClientCash>().Update(clientCash); var clientCashFlow = new ClientCashFlow() { ClientId = dto.AgentId, CoinId = dto.CoinId, Total = clientCash.Total, Amount = dto.Amount, Matched = false, MoenyAction = moneyAction }; _unitOfWork.GenericRepository <ClientCashFlow>().Insert(clientCashFlow); }
public bool ExchangeForClient(int clientId, int sellingCoinId, int purchasingCoinId, decimal firstAmount) { try { int treasuryId = _appSession.GetCurrentTreasuryId(); var secondCoinAmount = CalcForFirstCoin(sellingCoinId, purchasingCoinId, firstAmount); var mainCoin = _unitOfWork.GenericRepository <BranchCash>().FindBy(c => c.IsMainCoin == true).FirstOrDefault(); var firstCoinExchange = _unitOfWork.GenericRepository <ClientCash>().FindBy(c => c.CoinId == sellingCoinId && c.ClientId == clientId).FirstOrDefault(); var secoundCoinExchange = _unitOfWork.GenericRepository <ClientCash>().FindBy(c => c.CoinId == purchasingCoinId && c.ClientId == clientId).FirstOrDefault(); _unitOfWork.CreateTransaction(); var exchange = new Exchange() { BranchId = BranchHelper.Id, FirstCoinId = sellingCoinId, SecoundCoinId = purchasingCoinId, AmountOfFirstCoin = firstAmount, AmoutOfSecoundCoin = secondCoinAmount, MainCoinId = mainCoin.CoinId, }; _unitOfWork.GenericRepository <Exchange>().Insert(exchange); var clientCaches = _unitOfWork.GenericRepository <ClientCash>().FindBy(c => c.ClientId == clientId); var branchCashSellingCoin = clientCaches.Where(c => c.CoinId == sellingCoinId).FirstOrDefault(); branchCashSellingCoin.Total -= firstAmount; _unitOfWork.GenericRepository <ClientCash>().Update(branchCashSellingCoin); var branchCashpurhesCoin = clientCaches.Where(c => c.CoinId == purchasingCoinId).FirstOrDefault(); branchCashpurhesCoin.Total += secondCoinAmount; _unitOfWork.GenericRepository <ClientCash>().Update(branchCashpurhesCoin); var moneyAction = new MoneyAction() { ExchangeId = exchange.Id }; _unitOfWork.GenericRepository <MoneyAction>().Insert(moneyAction); var clientCashFlowForFirstCoin = new ClientCashFlow() { ClientId = clientId, MoenyAction = moneyAction, CoinId = sellingCoinId, Total = branchCashSellingCoin.Total, Amount = -firstAmount }; _unitOfWork.GenericRepository <ClientCashFlow>().Insert(clientCashFlowForFirstCoin); var clientCashFlowForSecondCoin = new ClientCashFlow() { ClientId = clientId, CoinId = purchasingCoinId, MoenyAction = moneyAction, Total = branchCashpurhesCoin.Total, Amount = secondCoinAmount }; _unitOfWork.GenericRepository <ClientCashFlow>().Insert(clientCashFlowForSecondCoin); _unitOfWork.Save(); _unitOfWork.Commit(); return(true); } catch (Exception ex) { _unitOfWork.Rollback(); return(false); } }