示例#1
0
        public async Task <int> WithdrawGameCredit(long _MemberSrno, decimal WithdrawAmount)
        {
            using (var dbContextTransaction = _db.Database.BeginTransaction())
            {
                try
                {
                    var ISUserExist = _db.MstUserAccount.Where(x => x.MemberSrno == _MemberSrno && x.Status == "ACTIVE").Any();

                    if (ISUserExist)
                    {
                        var UserWalletData         = _db.MstUserWallet.Where(x => x.MemberSrno == _MemberSrno).FirstOrDefault();
                        var UserDetails            = _db.MstUserAccount.Where(x => x.MemberSrno == _MemberSrno).FirstOrDefault();
                        var UserGameAccountDetails = _db.MstUserGameAccount.Where(x => x.MemberSrno == _MemberSrno).FirstOrDefault();

                        var TransactionID = new Guid().ToString();
                        //CALL 998 API TO TRANSFER CASH CREDIT TO GAME CREDIT
                        var result = await _intergration.WithdrawGameCredit(UserGameAccountDetails.GameId, WithdrawAmount, TransactionID);

                        if (result.Error == 0)
                        {
                            // add new log from cash credit transaction
                            var log_user_tracking_wallet = new LogUserTrackingWallet
                            {
                                MemberSrno         = _MemberSrno,
                                WalletFrom         = "GAME WALLET",
                                WalletTo           = "CASH WALLET",
                                TransactionType    = 5,
                                PreviousAmount     = UserWalletData.CashCredit,
                                TransactionAmount  = WithdrawAmount,
                                CurrentTotalAmount = UserWalletData.CashCredit + WithdrawAmount,
                                IsDeduct           = false,
                                Description        = string.Format("MEMBER:{0} WITHDRAWAL GAME CREDIT INTO CASH WALLET WITH AMOUNT:{1} AT:{2}", UserDetails.LoginId, WithdrawAmount, DateTime.Now),
                                CreatedDateTime    = DateTime.Now,
                            };

                            //add new log for game credit transaction
                            var log_user_game_credit_transaction = new LogUserGameCreditTransaction
                            {
                                GameApi         = "998 API",
                                TrasactionId    = TransactionID,
                                MemberSrno      = _MemberSrno,
                                Player          = UserGameAccountDetails.GameId,
                                TransferAmount  = result.Amount,
                                BeforeAmount    = result.Before,
                                AfterAmount     = result.After,
                                TransactionType = "WITHDRAWAL",
                                Status          = "SUCCESS",
                                TransferDate    = DateTime.Now
                            };

                            //DEDUCT TRANSFER AMOUNT FROM USER CASH WALLET
                            var UserWalletDetails = _db.MstUserWallet.Where(x => x.MemberSrno == _MemberSrno).FirstOrDefault();
                            UserWalletDetails.CashCredit += WithdrawAmount;


                            //Update all the changes into database
                            _db.LogUserTrackingWallet.Add(log_user_tracking_wallet);
                            _db.LogUserGameCreditTransaction.Add(log_user_game_credit_transaction);
                            await _db.SaveChangesAsync();

                            dbContextTransaction.Commit();

                            return(Models_General.SUCC_WITHDRAWAL_GAME_CREDIT);
                        }

                        return(Models_General.ERR_SERVER_BUSY_INTERNAL_ERROR);
                    }

                    return(Models_General.ERR_USER_NOT_FOUND);
                }
                catch (Exception ex)
                {
                    dbContextTransaction.Rollback();
                    var new_error = new LogErrorSystem
                    {
                        Title           = "Withdraw Game Credit",
                        Details         = ex.Message + "/" + ex.StackTrace,
                        Context         = _accessor.ActionContext.HttpContext.Connection.RemoteIpAddress.ToString(),
                        CreatedDateTime = DateTime.Now,
                    };
                    _db.LogErrorSystem.Add(new_error);
                    _db.SaveChanges();
                    return(Models_General.ERR_SERVER_BUSY_INTERNAL_ERROR);
                }
            }
        }
        public async Task <int> RecollectGameWalletAmounts()
        {
            try
            {
                var UserGameAccounts = _db.MstUserGameAccount.ToList();

                foreach (var useraccount in UserGameAccounts)
                {
                    var balance = await _intergration.GetBalance(useraccount.GameId);



                    if (balance.Error == 0)
                    {
                        var founduserwallet = _db.MstUserWallet.Where(x => x.MemberSrno == useraccount.MemberSrno).FirstOrDefault();

                        if (founduserwallet != null)
                        {
                            var TransactionID = new Guid().ToString();
                            var result        = await _intergration.WithdrawGameCredit(useraccount.GameId, balance.Balance, TransactionID);

                            var UserDetails = _db.MstUserAccount.Where(x => x.MemberSrno == useraccount.MemberSrno).FirstOrDefault();
                            if (result.Error == 0)
                            {
                                // add new log from cash credit transaction
                                var log_user_tracking_wallet = new LogUserTrackingWallet
                                {
                                    MemberSrno         = useraccount.MemberSrno,
                                    WalletFrom         = "GAME WALLET",
                                    WalletTo           = "CASH WALLET",
                                    TransactionType    = 5,
                                    PreviousAmount     = founduserwallet.CashCredit,
                                    TransactionAmount  = balance.Balance,
                                    CurrentTotalAmount = founduserwallet.CashCredit + balance.Balance,
                                    IsDeduct           = false,
                                    Description        = string.Format("MEMBER:{0} WITHDRAWAL GAME CREDIT INTO CASH WALLET WITH AMOUNT:{1} AT:{2}", UserDetails.LoginId, balance.Balance, DateTime.Now),
                                    CreatedDateTime    = DateTime.Now,
                                };

                                //add new log for game credit transaction
                                var log_user_game_credit_transaction = new LogUserGameCreditTransaction
                                {
                                    GameApi         = "998 API",
                                    TrasactionId    = TransactionID,
                                    MemberSrno      = useraccount.MemberSrno,
                                    Player          = useraccount.GameId,
                                    TransferAmount  = result.Amount,
                                    BeforeAmount    = result.Before,
                                    AfterAmount     = result.After,
                                    TransactionType = "WITHDRAWAL",
                                    Status          = "SUCCESS",
                                    TransferDate    = DateTime.Now
                                };

                                founduserwallet.CashCredit += balance.Balance;
                                _db.LogUserTrackingWallet.Add(log_user_tracking_wallet);
                                _db.LogUserGameCreditTransaction.Add(log_user_game_credit_transaction);
                            }
                        }
                        else
                        {
                            continue;
                        }
                    }
                }



                await _db.SaveChangesAsync();

                return(Models_General.SUCC_RECOLLECT_ALL_GAMER_WALLET_BALANCE);
            }
            catch (Exception ex)
            {
                var new_error = new LogErrorSystem
                {
                    Title           = "Recollect Game Wallets Amount",
                    Details         = ex.Message + "/" + ex.StackTrace,
                    Context         = _accessor.ActionContext.HttpContext.Connection.RemoteIpAddress.ToString(),
                    CreatedDateTime = DateTime.Now,
                };
                _db.LogErrorSystem.Add(new_error);
                _db.SaveChanges();
                return(Models_General.ERR_SERVER_BUSY_INTERNAL_ERROR);
            }
        }