Esempio n. 1
0
        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);
            }
        }
        public async Task <Tuple <int, long> > UserRegisterNewAccount(string LoginID, string FullName, string Password, string Email, string Phonenumber, string CountryCode, string DOB, int Gender, string Upline)
        {
            using var dbContextTransaction = _db.Database.BeginTransaction();
            try
            {
                int temp       = 1;
                var RandomCode = "";
                do
                {
                    var tempcode = _common_services.GenerateRandomNumber(10);
                    if (IsRefcodeExist(tempcode))
                    {
                        temp = 1;
                    }
                    else
                    {
                        RandomCode = tempcode;
                        temp       = 0;
                    }
                }while (temp == 1);

                var gamelogin = "******" + RandomCode;

                if (Upline != null && !IsRefcodeExist(Upline))
                {
                    return(new Tuple <int, long>(Models_General.ERR_UPLINE_REFERCODE_NOT_EXIST, 0));
                }
                else if (IsUsernameExist(LoginID))
                {
                    return(new Tuple <int, long>(Models_General.ERR_USERNAME_EXIST, 0));
                }
                else if (IsPhoneExist(Phonenumber))
                {
                    return(new Tuple <int, long>(Models_General.ERR_PHONENUMBER_EXIST, 0));
                }
                else if (IsEmailExist(Email))
                {
                    return(new Tuple <int, long>(Models_General.ERR_EMAIL_EXIST, 0));
                }

                //This will be the main table that all references will be linked to this MemberSrno so we need it to be the first table to store in our database and get the MemberSrno
                var UserAccount = new MstUserAccount
                {
                    LoginId      = LoginID,
                    Password     = Password,
                    Status       = "ACTIVE",
                    AccountType  = "MEMBER",
                    GameRegister = 0
                };
                //Add this into database first so that we can retrive the MemberSrno
                _db.MstUserAccount.Add(UserAccount);
                _db.SaveChanges();

                //Register a new account into our system

                var UserDetails = new MstUser {
                };


                if (Upline != null && Upline != "")
                {
                    var UplineDetails = _db.MstUser.Where(x => x.RefCode.Equals(Upline)).FirstOrDefault();
                    var UplineAccount = _db.MstUserAccount.Where(x => x.MemberSrno.Equals(UplineDetails.MemberSrno)).FirstOrDefault();

                    UserDetails = new MstUser
                    {
                        MemberSrno   = UserAccount.MemberSrno,
                        Name         = FullName,
                        Email        = Email,
                        Phone        = Phonenumber,
                        Country      = CountryCode,
                        DoB          = DOB,
                        Gender       = Gender,
                        RegisterDate = DateTime.Now,
                        RefCode      = RandomCode,
                        Upline       = UplineAccount.LoginId,
                        UplineId     = UplineAccount.MemberSrno,
                    };
                }
                else
                {
                    UserDetails = new MstUser
                    {
                        MemberSrno   = UserAccount.MemberSrno,
                        Name         = FullName,
                        Email        = Email,
                        Phone        = Phonenumber,
                        Country      = CountryCode,
                        DoB          = DOB,
                        Gender       = Gender,
                        RegisterDate = DateTime.Now,
                        RefCode      = RandomCode,
                    };
                }

                var UserCashWallet = new MstUserWallet
                {
                    MemberSrno = UserAccount.MemberSrno,
                    CashCredit = 0
                };

                //Set defualt password for game account
                var _GamePassword = "******";

                var UserGameAccount = new MstUserGameAccount
                {
                    MemberSrno      = UserAccount.MemberSrno,
                    GamePassword    = _GamePassword,
                    GameId          = gamelogin,
                    CreatedDateTime = DateTime.Now,
                };
                var UserGameWallet = new MstUserGameWallet
                {
                    MemberSrno = UserAccount.MemberSrno,
                    GameId     = gamelogin,
                    GameCredit = 0,
                };

                //Call 998 API to create a agame account
                var result = await _intergration.CreateNewPlayer(gamelogin, FullName, Email, Phonenumber, DOB, _GamePassword, CountryCode, Gender);

                if (result.Error == 0)
                {
                    //API Successfully Created an Account from the thrid party side then only allow to create an account into our database
                    _db.MstUser.Add(UserDetails);
                    _db.MstUserWallet.Add(UserCashWallet);
                    _db.MstUserGameAccount.Add(UserGameAccount);
                    _db.MstUserGameWallet.Add(UserGameWallet);
                    UserAccount.GameRegister = 1;
                    await _db.SaveChangesAsync();

                    dbContextTransaction.Commit();

                    return(new Tuple <int, long>(Models_General.SUCC_CREATE_ACCOUNT, UserAccount.MemberSrno));
                }
                else
                {
                    _db.MstUser.Add(UserDetails);
                    _db.MstUserWallet.Add(UserCashWallet);
                    _db.MstUserGameAccount.Add(UserGameAccount);
                    _db.MstUserGameWallet.Add(UserGameWallet);
                    UserAccount.GameRegister = 2;
                    await _db.SaveChangesAsync();

                    dbContextTransaction.Commit();

                    return(new Tuple <int, long>(Models_General.SUCC_CREATE_ACCOUNT_WITHOUT_GAME_ACCOUNT, UserAccount.MemberSrno));
                }
            }
            catch (Exception ex)
            {
                dbContextTransaction.Rollback();


                var new_error = new LogErrorSystem
                {
                    Title           = "User Register New Account",
                    Details         = ex.Message + "/" + ex.StackTrace,
                    Context         = _accessor.ActionContext.HttpContext.Connection.RemoteIpAddress.ToString(),
                    CreatedDateTime = DateTime.Now,
                };
                _db.LogErrorSystem.Add(new_error);
                _db.SaveChanges();
                return(new Tuple <int, long>(Models_General.ERR_SERVER_BUSY_INTERNAL_ERROR, 0));
            }
        }
Esempio n. 3
0
        public async Task <int> TopUpGameCredit(long _MemberSrno, decimal TransferAmount)
        {
            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();

                        if (UserWalletData.CashCredit >= TransferAmount)
                        {
                            var TransactionID = new Guid().ToString();
                            //CALL 998 API TO TRANSFER CASH CREDIT TO GAME CREDIT
                            var result = await _intergration.TransferGameCredit(UserGameAccountDetails.GameId, TransferAmount, TransactionID);

                            if (result.Error == 0)
                            {
                                // add new log from cash credit transaction
                                var log_user_tracking_wallet = new LogUserTrackingWallet
                                {
                                    MemberSrno         = _MemberSrno,
                                    WalletFrom         = "CASH WALLET",
                                    WalletTo           = "GAME WALLET",
                                    TransactionType    = 4,
                                    PreviousAmount     = UserWalletData.CashCredit,
                                    TransactionAmount  = TransferAmount,
                                    CurrentTotalAmount = UserWalletData.CashCredit - TransferAmount,
                                    IsDeduct           = true,
                                    Description        = string.Format("MEMBER:{0} TRANSFER CASH INTO GAME WALLET WITH AMOUNT:{1} AT:{2}", UserDetails.LoginId, TransferAmount, 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 = "DEPOSIT",
                                    Status          = "SUCCESS",
                                    TransferDate    = DateTime.Now
                                };

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


                                //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_TOPUP_GAME_CREDIT);
                            }

                            return(Models_General.ERR_SERVER_BUSY_INTERNAL_ERROR);
                        }

                        return(Models_General.ERR_INSUFFICIENT_CASH_BALANCE);
                    }

                    return(Models_General.ERR_USER_NOT_FOUND);
                }
                catch (Exception ex)
                {
                    dbContextTransaction.Rollback();
                    var new_error = new LogErrorSystem
                    {
                        Title           = "Topup 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> GetTicketsByFetch()
        {
            using var dbContextTransaction = _db.Database.BeginTransaction();
            try
            {
                int result;
                var dt           = DateTime.UtcNow;
                var strStartTime = dt.AddSeconds(-30).ToString("yyyy-MM-dd HH:mm:ss");
                var strEndTime   = dt.ToString("yyyy-MM-dd HH:mm:ss");



                var data = await _intergration.GetTicketsByFetch(strStartTime, strEndTime);

                if (data.Success == true)
                {
                    if (data.Result.Tickets.Length > 0)
                    {
                        foreach (var ticket in data.Result.Tickets)
                        {
                            var userfound  = _db.MstUserGameAccount.Where(x => x.GameId == ticket.MemberName).FirstOrDefault();
                            var userwallet = _db.MstUserWallet.Where(x => x.MemberSrno == userfound.MemberSrno).FirstOrDefault();

                            var log_tickets = new LogTickets
                            {
                                MemberSrno      = userfound.MemberSrno,
                                TicketSessionId = ticket.TicketSessionID,
                                TicketId        = ticket.TicketID,
                                GameType        = ticket.GameType,
                                RoundId         = ticket.RoundID,
                                Stake           = ticket.Stake,
                                StakeMoney      = ticket.StakeMoney,
                                Result          = ticket.Result,
                                Currency        = ticket.Currency,
                                StatementDate   = Convert.ToDateTime(ticket.StatementDate),
                                PlayerWinLoss   = ticket.PlayerWinLoss,
                                Vendor          = ticket.Vendor,
                                Product         = ticket.Product,
                                CreatedDateTime = DateTime.Now,
                            };

                            var winlose = new MstWinlose
                            {
                                MemberSrno      = userfound.MemberSrno,
                                WinloseAmount   = ticket.PlayerWinLoss,
                                StakeAmount     = ticket.StakeMoney,
                                Vendor          = ticket.Vendor,
                                Currency        = ticket.Currency,
                                GameType        = ticket.GameType,
                                Product         = ticket.Product,
                                CreatedDateTime = DateTime.Now,
                            };

                            if (userwallet.TurnoverAmount > 0)
                            {
                                if (Math.Abs(ticket.PlayerWinLoss) > userwallet.TurnoverAmount)
                                {
                                    userwallet.TurnoverAmount = 0;
                                }
                                else
                                {
                                    userwallet.TurnoverAmount -= Math.Abs(ticket.PlayerWinLoss);
                                }
                            }


                            if (userwallet.TwelveTurnoverAmount > 0)
                            {
                                if (Math.Abs(ticket.PlayerWinLoss) > userwallet.TwelveTurnoverAmount)
                                {
                                    userwallet.TwelveTurnoverAmount = 0;
                                }
                                else
                                {
                                    userwallet.TwelveTurnoverAmount -= Math.Abs(ticket.PlayerWinLoss);
                                }
                            }


                            _db.MstWinlose.Add(winlose);
                            _db.LogTickets.Add(log_tickets);
                            await _db.SaveChangesAsync();
                        }
                    }


                    dbContextTransaction.Commit();
                    result = Models_General.SUCC_GET_TICKETS;
                    return(result);
                }


                dbContextTransaction.Rollback();
                return(Models_General.ERR_GET_TICKETS);
            }
            catch (Exception ex)
            {
                dbContextTransaction.Rollback();

                var new_error = new LogErrorSystem
                {
                    Title           = "Get Tickets By Fetch",
                    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);
            }
        }