示例#1
0
        public async Task <ActionResult <(ErrorCode code, string message)> > Withdraw(string transactionid, [IsPositive] decimal amount)
        {
            if (ModelState.IsValid)
            {
                var casResult = _casinoManager.DecreaseBalance(amount, transactionid);

                if (casResult != ErrorCode.Success & _casinoManager.CheckTransaction(transactionid) != ErrorCode.Success)
                {
                    return(Ok(new
                    {
                        Code = casResult,
                        Message = Resources.DecreaseBalanceResources.ResourceManager.GetString(casResult.ToString()) ?? string.Empty
                    }));
                }

                var balResult = _gameManager.IncreaseBalance(amount, transactionid);

                if (balResult != ErrorCode.Success & _gameManager.CheckTransaction(transactionid) != ErrorCode.Success)
                {
                    var rollbackRes = await RollbackTransaction(transactionid, BalanceFactoryType.Casino);

                    if (!rollbackRes.success)
                    {
                        return(Ok(new
                        {
                            Code = rollbackRes.error,
                            Message = Resources.RollbackResources.ResourceManager.GetString(rollbackRes.error.ToString()) ?? string.Empty
                        }));
                    }

                    return(Ok(new
                    {
                        Code = rollbackRes.error,
                        Message = Resources.Resources.CasinoRolledBackWithDrawFailed
                    }));
                }

                return(Ok(new
                {
                    Code = ErrorCode.Success,
                    Message = Resources.Resources.WithdrawedSuccessfully
                }));
            }

            return(BadRequest());
        }
示例#2
0
        protected virtual void TryRollback(IBalanceManager balanceManager, string balanceName, string transactionId)
        {
            var checkErroCode = balanceManager.CheckTransaction(transactionId);

            if (checkErroCode == ErrorCode.Success)
            {
                var rollbackErrorCode = balanceManager.Rollback(transactionId);
                if (rollbackErrorCode == ErrorCode.Success)
                {
                    Exception.LogRollbackSuccess(balanceName);
                }
                else
                {
                    if (rollbackErrorCode == ErrorCode.UnknownError && TransactionRollbacked(balanceManager, transactionId))
                    {
                        Exception.LogRollbackSuccess(balanceName);
                    }
                    else
                    {
                        Exception.LogRollbackFailure(balanceName, rollbackErrorCode.ToString());
                    }
                }
            }
        }
示例#3
0
        private bool TransactionRollbacked(IBalanceManager balanceManager, string transactionId)
        {
            var checkRollbackErrorCode = balanceManager.CheckTransaction(transactionId);

            return(checkRollbackErrorCode == ErrorCode.TransactionRollbacked);
        }