public List <BetListDto> getLiveBetsByUserID(string userID) { List <BetListDto> BetList = new List <BetListDto>(); using (IDbConnection cn = new SqlConnection(WebConfigurationManager.ConnectionStrings["SQLData"].ConnectionString.ToString())) { string query = @" SELECT g.sn AS gameSn, g.title AS game ,g.gameStatus ,g.betModel ,t.sn AS topicSn,t.title AS topic ,c.sn AS choiceSn,c.choiceStr AS choice ,b.Odds ,b.money,b.sn as betSn ,(CASE pa.isTrue WHEN 1 THEN Round(pa.realMoney,2) when 2 then 0 ELSE b.money*-1 END) realmoney ,t.totalmoney as topicMoney,c.totalMoney as choiceMoney ,isnull(g.rake,0) as rake ,cu.name AS unit ,( case g.betModel WHEN 5 THEN case pa.isTrue WHEN 1 THEN '正解' ELSE '未定' END ELSE case c.isTrue WHEN 1 THEN '勝' WHEN 0 THEN '負' when 2 then '無效' ELSE '未定' END END ) AS isTrue ,(case c.isTrue WHEN 1 THEN 'true' WHEN 0 THEN 'false' when 2 then 'invalid' ELSE 'unknow' END) AS isTrueValue ,u.name as userID,b.comSn,g.allocation ,b.createDate as betDatetime,t.walk FROM dbo.bets b JOIN dbo.choices c ON c.sn=b.choiceSn JOIN dbo.topics t ON t.sn=b.topicSn JOIN dbo.games g ON g.sn=t.gameSn left join users u on u.sn = b.userSn right join users ug on ug.sn = g.userSn JOIN dbo.cfgUnit cu ON cu.sn=b.unitSn left join dbo.payouts pa on pa.betSn=b.sn WHERE ug.userID=@userID and b.valid in (1,2) order by betDatetime desc SELECT * FROM dbo.betCounts SELECT * FROM dbo.bets where bets.totalmoney IS NOT NULL "; using (var multi = cn.QueryMultiple(query, new { userID = userID })) { BetList = multi.Read <BetListDto>().ToList(); var betcount = multi.Read <betCountDto>().ToList(); var BetAll = multi.Read <betDto>().ToList(); foreach (var bet in BetList) { List <betCountDto> bto = new List <betCountDto>(); foreach (betCountDto count in betcount) { if (bet.betModel == 5 && count.betSn == bet.betSn && count.choiceCount != 0) { // betCountDto betdto = new betCountDto(); betCountDto betmodel = new betCountDto(); //betCount betcountdto = Mapper.Map<betCount>(count); betmodel.betSn = count.betSn; betmodel.choiceCount = count.choiceCount; betmodel.choiceStr = new ChoiceRepository().getdragon(count.choiceStr); betmodel.unitSn = count.unitSn; bto.Add(betmodel); } } if (bet.walk == 1) { bet.totalmoney = 0; foreach (var bl in BetAll) { if (bet.betSn <= bl.sn && bet.topicSn == bl.topicSn) { bet.totalmoney += ((float)bl.money * (100 - bet.allocation) / 100) / (float)bl.totalmoney * (float)bet.money; } } bet.totalmoney = (float)Math.Round((Decimal)bet.totalmoney, 2, MidpointRounding.AwayFromZero); } bet.betcountlist = bto; } } } return(BetList); }
public async System.Threading.Tasks.Task <ActionResult> LottoCreate(betViewModel bv) { aJaxDto ajd = new aJaxDto(); try { if (!ModelState.IsValid) { ajd.ErrorMsg = ""; foreach (var errs in ModelState.Values.Where(p => p.Errors.Count > 0).Select(p => p.Errors).Distinct()) { foreach (var e in errs) { ajd.ErrorMsg += e.ErrorMessage + "\n"; } //ajd.ErrorMsg += ""; } ajd.isTrue = false; throw new Exception("error"); } if (!User.Identity.GetEmailConfirmed() && !User.Identity.GetPhoneNumberConfirmed()) { ajd.ErrorMsg = "預測前須先完成Email驗證以及手機驗證\n請先至會員中心進行Email驗證和手機驗證,謝謝"; ajd.isTrue = false; throw new Exception("error"); } if (!User.Identity.GetEmailConfirmed()) { ajd.ErrorMsg = "預測前須先完成Email驗證\n請先至會員中心進行Email驗證,謝謝"; ajd.isTrue = false; throw new Exception("error"); } if (!User.Identity.GetPhoneNumberConfirmed()) { ajd.ErrorMsg = "預測前須先完成手機驗證\n請先至會員中心進行手機驗證,謝謝"; ajd.isTrue = false; throw new Exception("error"); } int?bvcount = 0; foreach (var bvlt in bv.betList) { if (bvlt.strsn != "5") { bvcount += bvlt.count; } } if (bvcount == 0) { ajd.ErrorMsg = "請在填空單選擇一個以上的選項"; ajd.isTrue = false; throw new Exception("error"); } double moneyclcik = 0; for (var bi = 0; bi < bv.betList.Count; bi++) { if (bi == 0) { moneyclcik = (double)bv.betList[bi].money; } else { if (bv.betList[bi].money != moneyclcik) { ajd.ErrorMsg = "請勿竄改前端資料"; ajd.isTrue = false; throw new Exception("error"); } } Regex regex = new Regex(@"^\+?[0-9]{1,10}[0][0]$|^$"); Match match = regex.Match(bv.betList[bi].money.ToString()); if (!match.Success) { ajd.ErrorMsg = "請勿竄改前端資料"; ajd.isTrue = false; throw new Exception("error"); } } List <betDto> bet_list = new List <betDto>(); GamesRepository _game = new GamesRepository(); int firstChoiceSn = bv.betList.First().getChoiceSn(System.Web.Configuration.WebConfigurationManager.AppSettings["encryptedKey"]); gameDto gd = await _game.GetGameDetailByChoiceSn(firstChoiceSn); double Assets = new AssetsRepository().getAssetsByUserID(User.Identity.GetUserId(), 1); Session["Assets"] = new AssetsRepository().getAssetsListByUserID(User.Identity.GetUserId()); //bv.encryptedKey = System.Web.Configuration.WebConfigurationManager.AppSettings["encryptedKey"]; betDto bet = new betDto(); bet.userId = User.Identity.GetUserId(); bet.unitSn = 1; bet.comSn = 1; bet.money = bv.betList[0].money; bet.choiceSn = bv.betList[0].getChoiceSn(System.Web.Configuration.WebConfigurationManager.AppSettings["encryptedKey"]); if (bet.choiceSn.HasValue) { topicDto t = await _game.GetTopicByChoiceSn(bet.choiceSn.Value); if (t != null) { bet.topicSn = t.sn; } } bet.gameSn = gd.sn; List <betCountDto> betlistmodel = new List <betCountDto>(); foreach (var b in bv.betList) { betCountDto betcount = new betCountDto(); betcount.betSn = bet.choiceSn; betcount.choiceStr = b.strsn; betcount.unitSn = 1; betcount.choiceCount = b.count; betlistmodel.Add(betcount); } bet.betCount = betlistmodel; if (Assets < bet.money) { ajd.ErrorMsg = "剩餘魚骨幣不足"; ajd.isTrue = false; throw new Exception("error"); } else { Assets -= bet.money.Value; } if (!gd.canbet) { ajd.ErrorMsg = "不可預測"; ajd.isTrue = false; throw new Exception("error"); } foreach (topicDto t in gd.topicList) { if (t.choiceList.Where(p => p.sn == bet.choiceSn).Count() > 0) { if (!t.canbet) { ajd.ErrorMsg = "不可預測"; ajd.isTrue = false; throw new Exception("error"); } } } bet_list.Add(bet); /* foreach (var b in bv.betList) * { * if (!b.money.HasValue || b.money <= 0) * continue; * //bv.encryptedKey = System.Web.Configuration.WebConfigurationManager.AppSettings["encryptedKey"]; * betDto bet = new betDto(); ; * bet.userId = User.Identity.GetUserId(); * bet.unitSn = 1; * bet.comSn = 1; * bet.money = b.money; * bet.choiceSn = b.getChoiceSn(System.Web.Configuration.WebConfigurationManager.AppSettings["encryptedKey"]); * if (bet.choiceSn.HasValue) * { * topicDto t = await _game.GetTopicByChoiceSn(bet.choiceSn.Value); * if (t != null) * { * bet.topicSn = t.sn; * } * } * bet.gameSn = gd.sn; * * if (Assets < bet.money) * { * ajd.ErrorMsg = "剩餘彩金不足"; * ajd.isTrue = false; * throw new Exception("error"); * } * else * { * Assets -= bet.money.Value; * } * * if (!gd.canbet) * { * ajd.ErrorMsg = "不可下注"; * ajd.isTrue = false; * throw new Exception("error"); * } * * foreach (topicDto t in gd.topicList) * { * if (t.choiceList.Where(p => p.sn == bet.choiceSn).Count() > 0) * { * if (!t.canbet) * { * ajd.ErrorMsg = "不可下注"; * ajd.isTrue = false; * throw new Exception("error"); * } * } * } * bet_list.Add(bet); * }*/ foreach (var betlist in bet_list) { bool isTrue = await _game.CreateBet(betlist); if (isTrue) { ajd.isTrue = isTrue; } else { ajd.ErrorMsg = "系統錯誤,請重整後再重新預測"; throw new Exception("error"); } } if (ajd.isTrue) { Session["Assets"] = new AssetsRepository().getAssetsListByUserID(User.Identity.GetUserId()); new SignalRHelper().UpdateChoiceMoney(gd, encryptedKey, gd.md5GameSn); } else { ajd.ErrorMsg = "魚骨幣發生問題,請重整後再重新預測"; throw new Exception("error"); } return(Json(ajd)); } catch { return(Json(ajd)); } }