コード例 #1
0
        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));
            }
        }
コード例 #2
0
        public async Task <Tuple <int, int> > CheckUserGameRegister()
        {
            try
            {
                var UserAccounts = _db.MstUserAccount.ToList();
                int count        = 0;

                foreach (var useraccount in UserAccounts)
                {
                    if (useraccount.GameRegister == 2)
                    {
                        var  UserDetails        = _db.MstUser.Where(x => x.MemberSrno == useraccount.MemberSrno).FirstOrDefault();
                        var  GameAccountDetails = _db.MstUserGameAccount.Where(x => x.MemberSrno == useraccount.MemberSrno).FirstOrDefault();
                        var  GameWalletDetails  = _db.MstUserGameWallet.Where(x => x.MemberSrno == useraccount.MemberSrno).FirstOrDefault();
                        bool temp_result        = false;
                        do
                        {
                            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;

                            var result = await _intergration.CreateNewPlayer(gamelogin, UserDetails.Name, UserDetails.Email, UserDetails.Phone, UserDetails.DoB, GameAccountDetails.GamePassword, UserDetails.Country, UserDetails.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
                                var new_recreate_user = new LogRecreateUser
                                {
                                    MemberSrno           = GameAccountDetails.MemberSrno,
                                    LoginId              = useraccount.LoginId,
                                    PreviousGameId       = GameAccountDetails.GameId,
                                    PreviousGamePassword = GameAccountDetails.GamePassword,
                                    CurrentGameId        = gamelogin,
                                    CurrentGamePassword  = GameAccountDetails.GamePassword,
                                    Status          = true,
                                    StatusCode      = result.Error,
                                    Message         = result.Message,
                                    CreatedDateTime = DateTime.Now,
                                };
                                _db.LogRecreateUser.Add(new_recreate_user);

                                temp_result = true;
                                useraccount.GameRegister  = 1;
                                GameAccountDetails.GameId = gamelogin;
                                GameWalletDetails.GameId  = gamelogin;
                                UserDetails.RefCode       = RandomCode;

                                count++;
                            }
                            else
                            {
                                var new_recreate_user_error = new LogRecreateUser
                                {
                                    MemberSrno           = GameAccountDetails.MemberSrno,
                                    LoginId              = useraccount.LoginId,
                                    PreviousGameId       = GameAccountDetails.GameId,
                                    PreviousGamePassword = GameAccountDetails.GamePassword,
                                    CurrentGameId        = gamelogin,
                                    CurrentGamePassword  = GameAccountDetails.GamePassword,
                                    Status          = false,
                                    StatusCode      = result.Error,
                                    Message         = result.Message,
                                    CreatedDateTime = DateTime.Now,
                                };
                                _db.LogRecreateUser.Add(new_recreate_user_error);
                            }
                        } while (temp_result == false);
                    }
                }
                await _db.SaveChangesAsync();

                return(new Tuple <int, int>(Models_General.SUCC_CHECK_USER_GAME_REGISTER, count));
            }
            catch (Exception ex)
            {
                var new_error = new LogErrorSystem
                {
                    Title           = "Check User Game 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, int>(Models_General.ERR_SERVER_BUSY_INTERNAL_ERROR, 0));
            }
        }