public async System.Threading.Tasks.Task <ActionResult> Create(betViewModel bv) { aJaxDto ajd = new aJaxDto(); try { if (User.Identity.GetUserId() == null) { ajd.ErrorMsg = "預測前須先登入\n請先至會員登入中心進行登入註冊,謝謝"; ajd.isTrue = false; ajd.ErrorCode = 2; throw new Exception("error"); } 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"); } 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()); //竄改 int[] bvarray = new int[] { 2, 2, 2, 4, 5 }; if (gd.betModel == 6) { int bj = 0; double moneyclcik = 0; for (var bi = 0; bi < 5; bi++) { for (int i = bj; i < bj + bvarray[bi]; i++) { if (bv.betList[i].money != null) { Regex regex = new Regex(@"^\+?[0-9]{1,10}[0][0]$|^$"); Match match = regex.Match(bv.betList[i].money.ToString()); if (!match.Success) { ajd.ErrorMsg = "請勿竄改前端資料"; ajd.isTrue = false; throw new Exception("error"); } if ((double)bv.betList[i].money <= 0) { ajd.ErrorMsg = "請勿竄改前端資料"; ajd.isTrue = false; throw new Exception("error"); } if (moneyclcik == 0) { moneyclcik = (double)bv.betList[i].money; } if (moneyclcik != (double)bv.betList[i].money) { ajd.ErrorMsg = "請勿竄改前端資料"; ajd.isTrue = false; throw new Exception("error"); } } } if (bi < 4) { bj += 2; } else if (bi == 4) { bj += 4; } else { bj += 5; } } } double nabobMoney = 0; 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 { if (gd.betModel != 6) { 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) { bool canbet = (t.walk == 1) ? true : t.canbet; //t.canbet = (t.walk == 1) ? true : t.canbet; if (!canbet) { ajd.ErrorMsg = "不可預測"; ajd.isTrue = false; throw new Exception("error"); } } } bet_list.Add(bet); } if (gd.betModel != 6) { foreach (var bet in bet_list) { bool isTrue = await _game.CreateBet(bet); if (isTrue) { ajd.isTrue = isTrue; } else { ajd.ErrorMsg = "系統錯誤,請重整後再重新預測"; throw new Exception("error"); } } } else { var betm = bet_list.Where(x => x.money != null).ToList(); bool isTrue = await _game.NabobCreateBet(betm); 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)); } }
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)); } }