Пример #1
0
        public bool BetCheck(SqlTransaction trans = null)
        {
            //check close time
            var item = CasinoItem.GetCasinoItem(CasinoItemGuid);

            if (item == null)
            {
                return(false);
            }

            if (DateTime.Now > item.CloseTime)
            {
                return(false);
            }

            if (BetAmount.HasValue && BetAmount <= 0)
            {
                return(false);
            }

            //check user account
            if (BetAmount.HasValue)
            {
                var gamber = new Gambler(UserID, trans);
                if (gamber.Cash < BetAmount.Value)
                {
                    return(false);
                }
            }

            return(true);
        }
Пример #2
0
        //public static int GetGamblerRPByUserID(int userID, Guid? leagueGuid = null)
        //{
        //    if (leagueGuid.HasValue)
        //        return DataAccess.Gambler.GetGamblerRPByUserID(userID, leagueGuid.Value);
        //    return DataAccess.Gambler.GetGamblerRPByUserID(userID);
        //}

        //public static void GamblerStatistics()
        //{
        //    var listGambler = GetGamblers();
        //    var listCasinoGambler = CasinoGambler.GetCasinoGamblers();

        //    var listCasinoCamblerContest = CasinoGambler.GetCasinoGamblers(ConfigGlobal.DefaultLeagueID);

        //    if (listCasinoCamblerContest != null && listCasinoCamblerContest.Count > 0)
        //    {
        //        listCasinoCamblerContest = CasinoGambler.SortCasinoGambler(listCasinoCamblerContest);
        //    }

        //    if (listGambler != null && listGambler.Count > 0 && listCasinoGambler != null && listCasinoGambler.Count > 0)
        //    {
        //        foreach (var g in listGambler)
        //        {
        //            var cg = listCasinoGambler.Find(
        //                delegate (CasinoGambler casinoGambler) { return casinoGambler.UserID.Equals(g.UserID); });

        //            if (cg != null)
        //                g.InitGambler(cg);

        //            var cgc = listCasinoCamblerContest.Find(
        //                delegate (CasinoGambler casinoGambler) { return casinoGambler.UserID.Equals(g.UserID); });

        //            if (cgc != null)
        //                g.ContestRank = cgc.Rank;
        //            else
        //                g.ContestRank = null;

        //            g.Update();
        //        }
        //    }
        //}

        public static void GamblerStatistics(int id)
        {
            var g  = new Gambler(id);
            var cg = CasinoGambler.GetCasinoGamblers().Find(x => x.UserID.Equals(id));

            CasinoGambler cgc = null;

            var listCasinoCamblerContest = CasinoGambler.GetCasinoGamblers(ConfigGlobal.DefaultLeagueID);

            if (listCasinoCamblerContest != null && listCasinoCamblerContest.Count > 0 &&
                listCasinoCamblerContest.Exists(x => x.UserID.Equals(id)))
            {
                listCasinoCamblerContest = CasinoGambler.SortCasinoGambler(listCasinoCamblerContest);

                cgc = listCasinoCamblerContest.Find(x => x.UserID.Equals(id));
            }

            if (cg != null)
            {
                g.InitGambler(cg);

                if (cgc != null)
                {
                    g.ContestRank = cgc.Rank;
                }
                else
                {
                    g.ContestRank = null;
                }
            }

            g.Update();
        }
Пример #3
0
        protected override void OnInitComplete(EventArgs e)
        {
            base.OnInitComplete(e);

            if (!ConfigGlobal.PluginActive
                && Request.Url.LocalPath.ToLower().IndexOf("default.aspx", StringComparison.OrdinalIgnoreCase) < 0)
            {
                if (!AdminPage)
                    Response.Redirect("Default.aspx");
            }

            // ReSharper disable once Html.PathError
            if (AnonymousRedirect && userid == -1) { Response.Redirect("/login.aspx"); }

            //Set Master Page Info
            var master = Master as DefaultMaster;

            if (master != null)
            {
                var masterPage = master;

                masterPage.UserId = userid;
                masterPage.UserName = username;
                masterPage.UserKey = userkey;
            }

            if (userid != -1)
            {
                CurrentGambler = new Gambler(userid);
            }
        }
Пример #4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (UserId <= 0)
            {
                pnlMyCasino.Visible = false;
            }
            else
            {
                pnlMyCasino.Visible = true;

                var g = new Gambler(UserId);

                if (g != null)
                {
                    var strRp = g.RPBonus.HasValue ? $"(RP: {g.RPBonus.Value}) " : string.Empty;
                    var strRank = g.ContestRank.HasValue ? $"(Rank: {g.ContestRank.Value}) " : string.Empty;

                    ltrlMyGamblerInfo.Text =
                        $"<li class=\"LiTitle\">博彩币:<em style=\"font-size: 12px; margin: 0 2px\">{g.Cash.ToString("N2")}</em>{(string.IsNullOrEmpty(strRp) && string.IsNullOrEmpty(strRank) ? string.Empty : $"<br /><em style=\"font-size: 12px; margin: 0 2px\" title=\"博彩获得RP | 当前赛季总排名\">{strRp}{strRank}</em>")}</li>";
                }
            }

            #region HideCasinoSysNotice

            if (string.IsNullOrEmpty(ConfigGlobal.SysNotice))
            {
                pnlNotice.Visible = false;
            }

            #endregion
        }
Пример #5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(Request.QueryString["UserID"]))
            {
                BtnBet.Visible = false;
                BtnViewBet.Visible = true;
                BtnViewBonus.Visible = true;
                BtnViewBet.OnClientClick = $"window.location.href='MyBetLog.aspx?userid={UserId}'; return false;";
                BtnViewBonus.OnClientClick = $"window.location.href='MyBonusLog.aspx?userid={UserId}'; return false;";
            }
            else
            {
                BtnBet.Visible = true;
                BtnViewBet.Visible = false;
                BtnViewBonus.Visible = false;
            }

            if (UserId > 0)
            {
                var currentGamlber = new Gambler(UserId);

                ltrlTotalBet.Text = currentGamlber.TotalBet.ToString("N2");
                ltrlWin.Text = currentGamlber.Win.ToString();
                ltrlLose.Text = currentGamlber.Lose.ToString();
                ltrlEarning.Text = Bet.GetUserTotalWinCash(UserId).ToString("N2");
                ltrlCash.Text = currentGamlber.Cash.ToString("N2");

                ltrlQSB.Text = Users.GetUserExtCredits(UserId, 2).ToString("N2");
                ltrlRP.Text = Users.GetUserExtCredits(UserId, 4).ToString("f0");

                //UserInfo userInfo = AdminUsers.GetUserInfo(UserID);
                var myAvatar = Avatars.GetAvatarUrl(UserId, AvatarSize.Small);
                //if (userInfo.Avatar == string.Empty)
                //{
                //    imgAvatar.ImageUrl = "/images/common/noavatar_small.gif";
                //}
                //else if (userInfo.Avatar.ToLower().IndexOf(@"/") == 0)
                //{
                //    imgAvatar.ImageUrl = userInfo.Avatar;
                //}
                //else if (userInfo.Avatar.ToLower().IndexOf("http") >= 0)
                //{
                //    imgAvatar.ImageUrl = userInfo.Avatar;
                //}
                //else
                //{
                //    imgAvatar.ImageUrl = string.Format("/{0}", userInfo.Avatar);
                //}
                imgAvatar.ImageUrl = myAvatar;
                imgAvatar.AlternateText = UserName;

                hlUserName.Text = UserName;
            }
        }
Пример #6
0
        public void ReturnBet()
        {
            using (var conn = SQLConn.GetConnection())
            {
                conn.Open();
                var trans = conn.BeginTransaction();
                try
                {
                    var casinoItemGuid = DataAccess.CasinoItem.GetCasinoItemGuidByMatch(MatchGuid,
                                                                                        (int)CasinoType.SingleChoice, trans);
                    if (casinoItemGuid.HasValue)
                    {
                        var item   = CasinoItem.GetCasinoItem(casinoItemGuid.Value);
                        var banker = new Banker(item.BankerID);

                        var dtMatchBet = DataAccess.Bet.GetMatchAllBet(MatchGuid);

                        var totalBet = 0f;

                        foreach (DataRow dr in dtMatchBet.Rows)
                        {
                            if (!Convert.IsDBNull(dr["Bet"]))
                            {
                                var gambler = new Gambler(Convert.ToInt32(dr["UserID"]), trans);
                                gambler.Cash     += Convert.ToSingle(dr["Bet"]);
                                gambler.TotalBet -= Convert.ToSingle(dr["Bet"]);
                                gambler.Update(trans);

                                totalBet += Convert.ToSingle(dr["Bet"]);
                            }
                        }

                        banker.Cash -= totalBet;
                        banker.Update(trans);

                        DataAccess.Bet.DeleteBetByMatchGuid(MatchGuid, trans);
                        DataAccess.BetDetail.CleanBetDetail(trans);

                        trans.Commit();
                    }
                }
                catch
                {
                    trans.Rollback();
                }

                //conn.Close();
            }
        }
Пример #7
0
        public void Insert(string optionValue)
        {
            using (var conn = SQLConn.GetConnection())
            {
                conn.Open();
                var trans = conn.BeginTransaction();
                try
                {
                    if (BetCheck(trans))
                    {
                        //update gambler statistics
                        var gambler = new Gambler(UserID, trans);
                        gambler.TotalBet += BetAmount.GetValueOrDefault(0f);

                        if (BetAmount.HasValue)
                        {
                            gambler.Cash -= BetAmount.GetValueOrDefault(0f);
                        }
                        gambler.Update(trans);

                        var banker = new Banker(CasinoItem.GetCasinoItem(CasinoItemGuid).BankerID);
                        banker.Cash += BetAmount.GetValueOrDefault(0f);
                        banker.Update(trans);

                        var key = DataAccess.Bet.InsertBet(UserID, UserName, CasinoItemGuid, BetAmount, BetRate, trans);
                        MatchChoiceOption.SaveMatchChoiceOption(key, optionValue, trans);

                        trans.Commit();
                    }
                    else
                    {
                        throw new Exception("Failed to create bet (SingleChoice).");
                    }
                }
                catch
                {
                    trans.Rollback();
                }

                //conn.Close();
            }
        }
Пример #8
0
        //public static void CleanNoCasinoItemBet()
        //{
        //    using (var conn = SQLConn.GetConnection())
        //    {
        //        conn.Open();
        //        var trans = conn.BeginTransaction();
        //        try
        //        {
        //            DataAccess.Bet.CleanBet(trans);
        //            DataAccess.BetDetail.CleanBetDetail(trans);
        //            trans.Commit();
        //        }
        //        catch
        //        {
        //            trans.Rollback();
        //        }

        //        //conn.Close();
        //    }
        //}

        public static void ReturnBet(int key)
        {
            using (var conn = SQLConn.GetConnection())
            {
                conn.Open();
                var trans = conn.BeginTransaction();
                try
                {
                    var bet = new Bet(key);

                    if (bet.BetAmount.HasValue && bet.BetAmount >= 0f)
                    {
                        var betAmount = Convert.ToSingle(bet.BetAmount);

                        var banker  = new Banker(CasinoItem.GetCasinoItem(bet.CasinoItemGuid).BankerID);
                        var gambler = new Gambler(bet.UserID, trans);

                        gambler.Cash     += betAmount;
                        gambler.TotalBet -= betAmount;
                        banker.Cash      -= betAmount;

                        gambler.Update(trans);
                        banker.Update(trans);
                    }
                    else if (!bet.BetAmount.HasValue && !bet.Earning.HasValue && bet.EarningDesc == "RP+1")
                    {
                        Users.UpdateUserExtCredits(bet.UserID, 4, -1);
                    }

                    DataAccess.Bet.DeleteBetById(key, trans);
                    DataAccess.BetDetail.CleanBetDetail(trans);
                    trans.Commit();
                }
                catch
                {
                    trans.Rollback();
                }
            }
        }
Пример #9
0
        public void Insert(string optionValue)
        {
            using (var conn = SQLConn.GetConnection())
            {
                conn.Open();
                var trans = conn.BeginTransaction();
                try
                {
                    if (BetCheck(trans))
                    {
                        //update gambler statistics
                        var gambler = new Gambler(UserID, trans);
                        gambler.TotalBet += BetAmount.GetValueOrDefault(0f);

                        if (BetAmount.HasValue)
                            gambler.Cash -= BetAmount.GetValueOrDefault(0f);
                        gambler.Update(trans);

                        var banker = new Banker(CasinoItem.GetCasinoItem(CasinoItemGuid).BankerID);
                        banker.Cash += BetAmount.GetValueOrDefault(0f);
                        banker.Update(trans);

                        var key = DataAccess.Bet.InsertBet(UserID, UserName, CasinoItemGuid, BetAmount, BetRate, trans);
                        MatchChoiceOption.SaveMatchChoiceOption(key, optionValue, trans);

                        trans.Commit();
                    }
                    else
                        throw new Exception("Failed to create bet (SingleChoice).");
                }
                catch
                {
                    trans.Rollback();
                }

                //conn.Close();
            }
        }
Пример #10
0
        public bool BetCheck(SqlTransaction trans = null)
        {
            //check close time
            var item = CasinoItem.GetCasinoItem(CasinoItemGuid);

            if (item == null)
                return false;

            if (DateTime.Now > item.CloseTime)
                return false;

            if (BetAmount.HasValue && BetAmount <= 0)
                return false;

            //check user account
            if (BetAmount.HasValue)
            {
                var gamber = new Gambler(UserID, trans);
                if (gamber.Cash < BetAmount.Value)
                    return false;
            }

            return true;
        }
Пример #11
0
        //public static void CleanNoCasinoItemBet()
        //{
        //    using (var conn = SQLConn.GetConnection())
        //    {
        //        conn.Open();
        //        var trans = conn.BeginTransaction();
        //        try
        //        {
        //            DataAccess.Bet.CleanBet(trans);
        //            DataAccess.BetDetail.CleanBetDetail(trans);
        //            trans.Commit();
        //        }
        //        catch
        //        {
        //            trans.Rollback();
        //        }
        //        //conn.Close();
        //    }
        //}
        public static void ReturnBet(int key)
        {
            using (var conn = SQLConn.GetConnection())
            {
                conn.Open();
                var trans = conn.BeginTransaction();
                try
                {
                    var bet = new Bet(key);

                    if (bet.BetAmount.HasValue && bet.BetAmount >= 0f)
                    {
                        var betAmount = Convert.ToSingle(bet.BetAmount);

                        var banker = new Banker(CasinoItem.GetCasinoItem(bet.CasinoItemGuid).BankerID);
                        var gambler = new Gambler(bet.UserID, trans);

                        gambler.Cash += betAmount;
                        gambler.TotalBet -= betAmount;
                        banker.Cash -= betAmount;

                        gambler.Update(trans);
                        banker.Update(trans);
                    }
                    else if (!bet.BetAmount.HasValue && !bet.Earning.HasValue && bet.EarningDesc == "RP+1")
                    {
                        Users.UpdateUserExtCredits(bet.UserID, 4, -1);
                    }

                    DataAccess.Bet.DeleteBetById(key, trans);
                    DataAccess.BetDetail.CleanBetDetail(trans);
                    trans.Commit();
                }
                catch
                {
                    trans.Rollback();
                }
            }
        }
Пример #12
0
        protected void gvGambler_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            var tbCash = gvGambler.Rows[gvGambler.EditIndex].FindControl("tbCash") as TextBox;
            var tbWin = gvGambler.Rows[gvGambler.EditIndex].FindControl("tbWin") as TextBox;
            var tbLose = gvGambler.Rows[gvGambler.EditIndex].FindControl("tbLose") as TextBox;

            var key = gvGambler.DataKeys[gvGambler.EditIndex];
            if (key != null)
            {
                var gambler = new Gambler((int)key.Value);

                if (tbCash != null && tbWin != null && tbLose != null)
                {
                    try
                    {
                        gambler.Cash = Convert.ToSingle(tbCash.Text);
                        gambler.Win = Convert.ToInt16(tbWin.Text);
                        gambler.Lose = Convert.ToInt16(tbLose.Text);

                        gambler.Update();

                        ClientScript.RegisterClientScriptBlock(typeof(string), "success", "alert('修改玩家信息成功');", true);
                    }
                    catch
                    {
                        ClientScript.RegisterClientScriptBlock(typeof(string), "failed", "alert('修改玩家信息失败');", true);
                    }
                }
            }

            gvGambler.EditIndex = -1;

            BindData();
        }
Пример #13
0
        //public static int GetGamblerRPByUserID(int userID, Guid? leagueGuid = null)
        //{
        //    if (leagueGuid.HasValue)
        //        return DataAccess.Gambler.GetGamblerRPByUserID(userID, leagueGuid.Value);
        //    return DataAccess.Gambler.GetGamblerRPByUserID(userID);
        //}
        //public static void GamblerStatistics()
        //{
        //    var listGambler = GetGamblers();
        //    var listCasinoGambler = CasinoGambler.GetCasinoGamblers();
        //    var listCasinoCamblerContest = CasinoGambler.GetCasinoGamblers(ConfigGlobal.DefaultLeagueID);
        //    if (listCasinoCamblerContest != null && listCasinoCamblerContest.Count > 0)
        //    {
        //        listCasinoCamblerContest = CasinoGambler.SortCasinoGambler(listCasinoCamblerContest);
        //    }
        //    if (listGambler != null && listGambler.Count > 0 && listCasinoGambler != null && listCasinoGambler.Count > 0)
        //    {
        //        foreach (var g in listGambler)
        //        {
        //            var cg = listCasinoGambler.Find(
        //                delegate (CasinoGambler casinoGambler) { return casinoGambler.UserID.Equals(g.UserID); });
        //            if (cg != null)
        //                g.InitGambler(cg);
        //            var cgc = listCasinoCamblerContest.Find(
        //                delegate (CasinoGambler casinoGambler) { return casinoGambler.UserID.Equals(g.UserID); });
        //            if (cgc != null)
        //                g.ContestRank = cgc.Rank;
        //            else
        //                g.ContestRank = null;
        //            g.Update();
        //        }
        //    }
        //}
        public static void GamblerStatistics(int id)
        {
            var g = new Gambler(id);
            var cg = CasinoGambler.GetCasinoGamblers().Find(x => x.UserID.Equals(id));

            CasinoGambler cgc = null;

            var listCasinoCamblerContest = CasinoGambler.GetCasinoGamblers(ConfigGlobal.DefaultLeagueID);

            if (listCasinoCamblerContest != null && listCasinoCamblerContest.Count > 0 &&
                listCasinoCamblerContest.Exists(x => x.UserID.Equals(id)))
            {
                listCasinoCamblerContest = CasinoGambler.SortCasinoGambler(listCasinoCamblerContest);

                cgc = listCasinoCamblerContest.Find(x => x.UserID.Equals(id));
            }

            if (cg != null)
            {
                g.InitGambler(cg);

                if (cgc != null)
                    g.ContestRank = cgc.Rank;
                else
                    g.ContestRank = null;
            }

            g.Update();
        }
Пример #14
0
        public void ReturnBet()
        {
            using (var conn = SQLConn.GetConnection())
            {
                conn.Open();
                var trans = conn.BeginTransaction();
                try
                {
                    var casinoItemGuid = DataAccess.CasinoItem.GetCasinoItemGuidByMatch(MatchGuid,
                        (int)CasinoType.SingleChoice, trans);
                    if (casinoItemGuid.HasValue)
                    {
                        var item = CasinoItem.GetCasinoItem(casinoItemGuid.Value);
                        var banker = new Banker(item.BankerID);

                        var dtMatchBet = DataAccess.Bet.GetMatchAllBet(MatchGuid);

                        var totalBet = 0f;

                        foreach (DataRow dr in dtMatchBet.Rows)
                        {
                            if (!Convert.IsDBNull(dr["Bet"]))
                            {
                                var gambler = new Gambler(Convert.ToInt32(dr["UserID"]), trans);
                                gambler.Cash += Convert.ToSingle(dr["Bet"]);
                                gambler.TotalBet -= Convert.ToSingle(dr["Bet"]);
                                gambler.Update(trans);

                                totalBet += Convert.ToSingle(dr["Bet"]);
                            }
                        }

                        banker.Cash -= totalBet;
                        banker.Update(trans);

                        DataAccess.Bet.DeleteBetByMatchGuid(MatchGuid, trans);
                        DataAccess.BetDetail.CleanBetDetail(trans);

                        trans.Commit();
                    }
                }
                catch
                {
                    trans.Rollback();
                }

                //conn.Close();
            }
        }
Пример #15
0
        public void CalcBonus()
        {
            if (string.IsNullOrEmpty(ResultHome.ToString()) || string.IsNullOrEmpty(ResultAway.ToString()))
            {
                throw new Exception("You can not calc bonus without a match result");
            }

            using (var conn = SQLConn.GetConnection())
            {
                conn.Open();
                var trans = conn.BeginTransaction();

                try
                {
                    var itemGuid = DataAccess.CasinoItem.GetCasinoItemGuidByMatch(MatchGuid,
                        (int)CasinoType.SingleChoice, trans);

                    if (itemGuid.HasValue)
                    {
                        //single choice bonus
                        var item = CasinoItem.GetCasinoItem(itemGuid.Value);
                        var banker = new Banker(item.BankerID);

                        var totalEarning = 0f;

                        var betList = Bet.GetBetByCasinoItemGuid(itemGuid.Value, trans);

                        foreach (var bet in betList)
                        {
                            var dt = DataAccess.BetDetail.GetBetDetailByBetId(bet.ID);

                            if (dt != null)
                            {
                                var gambler = new Gambler(bet.UserID, trans);

                                if (bet.IsWin == null)
                                {
                                    var isWin = false;

                                    var dr = dt.Rows[0];

                                    if (dr["DetailName"].ToString() == MatchChoiceOption.HomeWinValue &&
                                        ResultHome > ResultAway)
                                        isWin = true;
                                    else if (dr["DetailName"].ToString() == MatchChoiceOption.DrawValue &&
                                             ResultHome == ResultAway)
                                        isWin = true;
                                    else if (dr["DetailName"].ToString() == MatchChoiceOption.AwayWinValue &&
                                             ResultHome < ResultAway)
                                        isWin = true;

                                    bet.IsWin = isWin;

                                    if (bet.BetAmount.HasValue)
                                    {
                                        totalEarning += bet.BetAmount.Value;

                                        if (isWin)
                                        {
                                            bet.Earning = bet.BetAmount * bet.BetRate;

                                            if (bet.Earning != null)
                                            {
                                                bet.EarningDesc = $"{bet.Earning.Value:N2}";

                                                totalEarning -= bet.Earning.Value;

                                                //add gambler cash

                                                gambler.Cash += bet.Earning.Value;
                                                gambler.Win++;

                                                banker.Cash -= bet.Earning.Value;
                                            }
                                        }
                                        else
                                        {
                                            gambler.Lose++;

                                            bet.Earning = 0;
                                            bet.EarningDesc = string.Empty;
                                        }
                                    }
                                }

                                bet.Update(trans);
                                gambler.Update(trans);
                            }
                        }

                        banker.Update(trans);

                        item.Earning = totalEarning;
                        item.Save(trans);
                    }

                    itemGuid = DataAccess.CasinoItem.GetCasinoItemGuidByMatch(MatchGuid, (int)CasinoType.MatchResult,
                        trans);

                    if (itemGuid.HasValue)
                    {
                        //match result bonus
                        var betList = Bet.GetBetByCasinoItemGuid(itemGuid.Value, trans);

                        var item = CasinoItem.GetCasinoItem(itemGuid.Value);
                        item.Earning = 0;
                        item.Save(trans);

                        foreach (var bet in betList)
                        {
                            var gambler = new Gambler(bet.UserID, trans);

                            var dt = DataAccess.BetDetail.GetBetDetailByBetId(bet.ID);

                            var betDetail = new MatchResultBetDetail(dt);

                            if (bet.IsWin == null)
                            {
                                if (betDetail.Home == ResultHome && betDetail.Away == ResultAway)
                                {
                                    //win
                                    bet.IsWin = true;
                                    bet.Earning = 0;
                                    bet.EarningDesc = "RP+1";

                                    gambler.Win++;

                                    //update user rp

                                    Users.UpdateUserExtCredits(bet.UserID, 4, 1);
                                }
                                else
                                {
                                    //lose
                                    bet.IsWin = false;
                                    bet.Earning = 0;
                                    bet.EarningDesc = string.Empty;

                                    gambler.Lose++;
                                }
                            }

                            bet.Update(trans);
                            gambler.Update(trans);
                        }
                    }

                    trans.Commit();
                }
                catch
                {
                    trans.Rollback();
                }
            }
        }
Пример #16
0
        public void CalcBonus()
        {
            if (string.IsNullOrEmpty(ResultHome.ToString()) || string.IsNullOrEmpty(ResultAway.ToString()))
            {
                throw new Exception("You can not calc bonus without a match result");
            }

            using (var conn = SQLConn.GetConnection())
            {
                conn.Open();
                var trans = conn.BeginTransaction();

                try
                {
                    var itemGuid = DataAccess.CasinoItem.GetCasinoItemGuidByMatch(MatchGuid,
                                                                                  (int)CasinoType.SingleChoice, trans);

                    if (itemGuid.HasValue)
                    {
                        //single choice bonus
                        var item   = CasinoItem.GetCasinoItem(itemGuid.Value);
                        var banker = new Banker(item.BankerID);

                        var totalEarning = 0f;

                        var betList = Bet.GetBetByCasinoItemGuid(itemGuid.Value, trans);

                        foreach (var bet in betList)
                        {
                            var dt = DataAccess.BetDetail.GetBetDetailByBetId(bet.ID);

                            if (dt != null)
                            {
                                var gambler = new Gambler(bet.UserID, trans);

                                if (bet.IsWin == null)
                                {
                                    var isWin = false;

                                    var dr = dt.Rows[0];

                                    if (dr["DetailName"].ToString() == MatchChoiceOption.HomeWinValue &&
                                        ResultHome > ResultAway)
                                    {
                                        isWin = true;
                                    }
                                    else if (dr["DetailName"].ToString() == MatchChoiceOption.DrawValue &&
                                             ResultHome == ResultAway)
                                    {
                                        isWin = true;
                                    }
                                    else if (dr["DetailName"].ToString() == MatchChoiceOption.AwayWinValue &&
                                             ResultHome < ResultAway)
                                    {
                                        isWin = true;
                                    }

                                    bet.IsWin = isWin;

                                    if (bet.BetAmount.HasValue)
                                    {
                                        totalEarning += bet.BetAmount.Value;

                                        if (isWin)
                                        {
                                            bet.Earning = bet.BetAmount * bet.BetRate;

                                            if (bet.Earning != null)
                                            {
                                                bet.EarningDesc = $"{bet.Earning.Value:N2}";

                                                totalEarning -= bet.Earning.Value;

                                                //add gambler cash

                                                gambler.Cash += bet.Earning.Value;
                                                gambler.Win++;

                                                banker.Cash -= bet.Earning.Value;
                                            }
                                        }
                                        else
                                        {
                                            gambler.Lose++;

                                            bet.Earning     = 0;
                                            bet.EarningDesc = string.Empty;
                                        }
                                    }
                                }

                                bet.Update(trans);
                                gambler.Update(trans);
                            }
                        }

                        banker.Update(trans);

                        item.Earning = totalEarning;
                        item.Save(trans);
                    }

                    itemGuid = DataAccess.CasinoItem.GetCasinoItemGuidByMatch(MatchGuid, (int)CasinoType.MatchResult,
                                                                              trans);

                    if (itemGuid.HasValue)
                    {
                        //match result bonus
                        var betList = Bet.GetBetByCasinoItemGuid(itemGuid.Value, trans);

                        var item = CasinoItem.GetCasinoItem(itemGuid.Value);
                        item.Earning = 0;
                        item.Save(trans);

                        foreach (var bet in betList)
                        {
                            var gambler = new Gambler(bet.UserID, trans);

                            var dt = DataAccess.BetDetail.GetBetDetailByBetId(bet.ID);

                            var betDetail = new MatchResultBetDetail(dt);

                            if (bet.IsWin == null)
                            {
                                if (betDetail.Home == ResultHome && betDetail.Away == ResultAway)
                                {
                                    //win
                                    bet.IsWin       = true;
                                    bet.Earning     = 0;
                                    bet.EarningDesc = "RP+1";

                                    gambler.Win++;

                                    //update user rp

                                    Users.UpdateUserExtCredits(bet.UserID, 4, 1);
                                }
                                else
                                {
                                    //lose
                                    bet.IsWin       = false;
                                    bet.Earning     = 0;
                                    bet.EarningDesc = string.Empty;

                                    gambler.Lose++;
                                }
                            }

                            bet.Update(trans);
                            gambler.Update(trans);
                        }
                    }

                    trans.Commit();
                }
                catch
                {
                    trans.Rollback();
                }
            }
        }