public async Task <int> UpdateGameWalletAmounts() { using var dbContextTransaction = _db.Database.BeginTransaction(); 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.MstUserGameWallet.Where(x => x.MemberSrno == useraccount.MemberSrno).FirstOrDefault(); if (founduserwallet != null) { founduserwallet.GameCredit = balance.Balance; } else { continue; } } } await _db.SaveChangesAsync(); dbContextTransaction.Commit(); return(Models_General.SUCC_GET_ALL_GAMER_WALLET_BALANCE); } catch (Exception ex) { dbContextTransaction.Rollback(); var new_error = new LogErrorSystem { Title = "Update Game Wallets Account", 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 <decimal> GetBalanceGameCredit(long _MemberSrno) { using var dbContextTransaction = _db.Database.BeginTransaction(); try { var ISUserExist = _db.MstUserAccount.Where(x => x.MemberSrno == _MemberSrno && x.Status == "ACTIVE").Any(); decimal data = -1; if (ISUserExist) { var UserGameAccountDetails = _db.MstUserGameAccount.Where(x => x.MemberSrno == _MemberSrno).FirstOrDefault(); var result = await _intergration.GetBalance(UserGameAccountDetails.GameId); if (result.Error == 0) { data = result.Balance; await _db.SaveChangesAsync(); dbContextTransaction.Commit(); return(data); } return(data); } return(Models_General.ERR_BALANCE_NOT_FOUND); } catch (Exception ex) { dbContextTransaction.Rollback(); var new_error = new LogErrorSystem { Title = "Retrieve Game Balance 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); } }