Esempio n. 1
0
 public void AddToQueue(UserCoinTransactionOrderDto userCoinTransactionOrderDto)
 {
     lock (Lock)
     {
         if (!PurchasingQueue.ContainsKey(userCoinTransactionOrderDto.Id))
         {
             PurchasingQueue.Add(userCoinTransactionOrderDto.Id, userCoinTransactionOrderDto);
         }
     }
 }
Esempio n. 2
0
 public void UpdateFromQueue(UserCoinTransactionOrderDto userCoinTransactionOrderDto)
 {
     lock (Lock)
     {
         if (PurchasingQueue.ContainsKey(userCoinTransactionOrderDto.Id))
         {
             PurchasingQueue[userCoinTransactionOrderDto.Id] = userCoinTransactionOrderDto;
         }
     }
 }
Esempio n. 3
0
        public VarlikResult Save(UserCoinTransactionOrderDto userCoinTransactionOrderDto)
        {
            if (userCoinTransactionOrderDto == null)
            {
                var result = new VarlikResult();
                result.Status = ResultStatus.MissingRequiredParamater;
                return(result);
            }

            userCoinTransactionOrderDto.CoinUnitPrice = Math.Abs(userCoinTransactionOrderDto.CoinUnitPrice);
            userCoinTransactionOrderDto.CoinAmount    = Math.Abs(userCoinTransactionOrderDto.CoinAmount);

            var transactionManager = new UserCoinTransactionLogManager();

            //get current max price of coin
            if (userCoinTransactionOrderDto.IdTransactionType == TransactionTypeEnum.CoinSales)
            {
                var maxPriceR = transactionManager.GetMaxPriceOfCoin(userCoinTransactionOrderDto.IdCoinType);
                if (maxPriceR.IsSuccess)
                {
                    if (maxPriceR.Data > 0)
                    {
                        var limit = maxPriceR.Data * 20;
                        if (userCoinTransactionOrderDto.CoinUnitPrice > limit)
                        {
                            var result = new VarlikResult();
                            result.Status = ResultStatus.AboveTheLimit;
                            return(result);
                        }
                    }
                }
            }
            var idUser = IdentityHelper.Instance.CurrentUserId;

            userCoinTransactionOrderDto.IdUser = idUser;

            // does user have this address
            if (userCoinTransactionOrderDto.IdTransactionType == TransactionTypeEnum.FromWallet)
            {
                var userManager = new UserManager();
                var hasAddressR = userManager.DoesUserHaveThisAddress(idUser, userCoinTransactionOrderDto.IdCoinType, userCoinTransactionOrderDto.ToWalletAddress);
                if (!hasAddressR.IsSuccess)
                {
                    return(hasAddressR);
                }
                if (!hasAddressR.Data)
                {
                    var result = new VarlikResult();
                    result.Status = ResultStatus.UserDoesNotHaveThisAddress;
                    return(result);
                }
            }
            else if (userCoinTransactionOrderDto.IdTransactionType == TransactionTypeEnum.ToWallet)
            {
                var userManager = new UserManager();
                var hasAddressR = userManager.DoesUserHaveThisAddress(idUser, userCoinTransactionOrderDto.IdCoinType, userCoinTransactionOrderDto.FromWalletAddress);
                if (!hasAddressR.IsSuccess || !hasAddressR.Data)
                {
                    var result = new VarlikResult();
                    result.Status = ResultStatus.UserDoesNotHaveThisAddress;
                    return(result);
                }
            }

            var push       = new List <TransactinOrderListDto>();
            var saveResult = _userCoinTransactionOrderOperation.MakeOrder(userCoinTransactionOrderDto, ref push);

            // push to order list
            if (saveResult.IsSuccess)
            {
                OrderPublisher orderPublisher = new OrderPublisher();
                foreach (var transactinOrderListDto in push)
                {
                    orderPublisher.PublishOrder(userCoinTransactionOrderDto.IdCoinType, transactinOrderListDto);
                }
            }

            //push to price list
            transactionManager.PushPrice(userCoinTransactionOrderDto.IdCoinType);

            return(saveResult);
        }
Esempio n. 4
0
        public VarlikResult Update(UserCoinTransactionOrderDto userCoinTransactionOrderDto)
        {
            var updateResult = _userCoinTransactionOrderOperation.Update(userCoinTransactionOrderDto);

            return(updateResult);
        }
 public VarlikResult Save([FromBody] UserCoinTransactionOrderDto userCoinTransactionOrderDto)
 {
     return(_userCoinTransactionOrderManager.Save(userCoinTransactionOrderDto));
 }