Esempio n. 1
0
        /// <summary>
        /// Created Address with optimistic lock
        /// </summary>
        /// <param name="repoQuery"></param>
        /// <param name="rpcClass"></param>
        /// <param name="walletId"></param>
        /// <param name="other"></param>
        /// <typeparam name="TBlockchainAddress"></typeparam>
        /// <returns></returns>
        public virtual async Task <ReturnObject> CreateAddressAsync <TBlockchainAddress>(
            IAddressRepository <TBlockchainAddress> repoQuery, IBlockchainRpc rpcClass, string walletId,
            string other = "") where TBlockchainAddress : BlockchainAddress
        {
            try
            {
                using (var walletRepository = VakapayRepositoryFactory.GetWalletRepository(DbConnection))
                {
                    var walletCheck = walletRepository.FindById(walletId);

                    if (walletCheck == null)
                    {
                        return new ReturnObject
                               {
                                   Status  = Status.STATUS_ERROR,
                                   Message = "Wallet Not Found"
                               }
                    }
                    ;
                }
                var resultsRPC = rpcClass.CreateNewAddress(other);
                if (resultsRPC.Status == Status.STATUS_ERROR)
                {
                    return(resultsRPC);
                }

                var address = resultsRPC.Data;

                //	TBlockchainAddress _newAddress = new TBlockchainAddress();

                var resultDB = await repoQuery.InsertAddress(address, walletId, other);

                //
                //if (result.Status == Status.StatusError)
                //{
                //	return new ReturnObject
                //	{
                //		Status = Status.StatusSuccess,
                //		Message = "Cannot Insert Address"
                //	};
                //}

                //update address into wallet db
                //wallet.WalletBusiness(VakapayRepositoryFactory);

                return(new ReturnObject
                {
                    Status = resultDB.Status,
                    Message = resultDB.Message
                });
            }
            catch (Exception e)
            {
                return(new ReturnObject
                {
                    Status = Status.STATUS_ERROR,
                    Message = e.Message
                });
            }
        }
        /// <summary>
        /// Created Address with optimistic lock
        /// </summary>
        /// <param name="rpcClass"></param>
        /// <param name="walletId"></param>
        /// <param name="other"></param>
        /// <returns></returns>
        public virtual ReturnObject CreateAddress(IBlockchainRpc rpcClass, string userId,
                                                  string other = "")
        {
            try
            {
                using (var dbConnection = SmartContractRepositoryFactory.GetDbConnection())
                {
                    if (dbConnection.State != ConnectionState.Open)
                    {
                        dbConnection.Open();
                    }

                    var userRepository = SmartContractRepositoryFactory.GetUserRepository(dbConnection);

                    var userCheck = userRepository.FindByIdUser(userId);

                    if (userCheck == null)
                    {
                        return new ReturnObject
                               {
                                   Status  = Status.STATUS_ERROR,
                                   Message = "User Not Found"
                               }
                    }
                    ;

                    var resultsRPC = rpcClass.CreateNewAddress(other);
                    if (resultsRPC.Status == Status.STATUS_ERROR)
                    {
                        return(resultsRPC);
                    }

                    var address = resultsRPC.Data;

                    return(new ReturnObject
                    {
                        Status = Status.STATUS_SUCCESS,
                        Data = address,
                        Message = "Can't update wallet " + userCheck.mem_id
                    });
                }
            }
            catch (Exception e)
            {
                return(new ReturnObject
                {
                    Status = Status.STATUS_ERROR,
                    Message = e.Message
                });
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Created Address with optimistic lock
        /// </summary>
        /// <param name="repoQuery"></param>
        /// <param name="rpcClass"></param>
        /// <param name="walletId"></param>
        /// <param name="other"></param>
        /// <typeparam name="TBlockchainAddress"></typeparam>
        /// <returns></returns>
        public virtual async Task <ReturnObject> CreateAddressAsync <TBlockchainAddress>(
            IAddressRepository <TBlockchainAddress> repoQuery, IBlockchainRpc rpcClass, string userId,
            string other = "") where TBlockchainAddress : BlockchainAddress
        {
            try
            {
                using (var userRepository = SmartContractRepositoryFactory.GetUserRepository(DbConnection))
                {
                    var walletCheck = userRepository.FindById(userId);

                    if (walletCheck == null)
                    {
                        return new ReturnObject
                               {
                                   Status  = Status.STATUS_ERROR,
                                   Message = "Wallet Not Found"
                               }
                    }
                    ;
                }

                var resultsRPC = rpcClass.CreateNewAddress(other);
                if (resultsRPC.Status == Status.STATUS_ERROR)
                {
                    return(resultsRPC);
                }

                var address = resultsRPC.Data;


                var resultDB = await repoQuery.InsertAddress(address, userId, other);


                return(new ReturnObject
                {
                    Status = resultDB.Status,
                    Message = resultDB.Message
                });
            }
            catch (Exception e)
            {
                return(new ReturnObject
                {
                    Status = Status.STATUS_ERROR,
                    Message = e.Message
                });
            }
        }