public async Task <ActionResult> Edit([Bind(Include = "BetServiceMatchNo,setno,champ,HomeTeamId,AwayTeamId,stime,status,date_reg,HomeScore,AwayScore,Hthomescore,HtAwayScore,resultstatus")] Match match) { if (ModelState.IsValid) { BetDatabase.Entry(match).State = EntityState.Modified; await BetDatabase.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.HomeTeamId = new SelectList(BetDatabase.Teams, "TeamId", "TeamName", match.HomeTeamId); ViewBag.AwayTeamId = new SelectList(BetDatabase.Teams, "TeamId", "TeamName", match.AwayTeamId); return(View(match)); }
public async Task <ActionResult> Edit([Bind(Include = "BetServiceMatchNo,SetNo,League,StartTime,GameStatus,AwayTeamId,HomeTeamId,RegistrationDate,HomeScore,AwayScore,HalfTimeHomeScore,HalfTimeAwayScore,ResultStatus")] Match game) { if (ModelState.IsValid) { BetDatabase.Entry(game).State = EntityState.Modified; await BetDatabase.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.AwayTeamId = new SelectList(BetDatabase.Teams, "TeamId", "TeamName", game.AwayTeamId); ViewBag.HomeTeamId = new SelectList(BetDatabase.Teams, "TeamId", "TeamName", game.HomeTeamId); return(View(game)); }
public ActionResult Edit(Terminal terminal) { //var _terminal = new Terminal() //{ // TerminalId = terminal.TerminalId, // IpAddress = terminal.IpAddress, // DateCreated = DateTime.Parse("terminal.DateCreated"), // isActive = false //}; if (ModelState.IsValid) { BetDatabase.Entry(terminal).State = EntityState.Modified; BetDatabase.SaveChanges(); return(RedirectToAction("Index")); } return(View(terminal)); }
public void score() { try { if (!AlreadyRunningUpdate) { //AlreadyRunningUpdate = true; DateTime start = DateTime.Now; foreach (var iURL in _resultUrls) { var req = (HttpWebRequest)WebRequest.Create(iURL); var res = (HttpWebResponse)req.GetResponse(); var stream = res.GetResponseStream(); var xmldoc = new XmlDocument(); xmldoc.Load(stream); var categoryList = xmldoc.SelectNodes("/scores/category"); int loops = 0; string goalServeMatchID = ""; foreach (XmlNode categoryNode in categoryList) { XmlNodeList matches = categoryNode.ChildNodes; foreach (XmlNode matchesNode in matches) { loops += 1; XmlNodeList games = matchesNode.ChildNodes; foreach (XmlNode gameNode in games) { string status = gameNode.Attributes["status"].InnerText.ToString(); if (status == "FT")//update for only full time games { XmlNode home = gameNode.ChildNodes[0]; XmlNode away = gameNode.ChildNodes[1]; XmlNode halftime = gameNode.ChildNodes[3]; string hostTeam = home.Attributes["name"].InnerText; string awayTeam = away.Attributes["name"].InnerText; goalServeMatchID = gameNode.Attributes["id"].InnerText; try { int homeGoals = Convert.ToInt16(home.Attributes["goals"].InnerText); int awayGoals = Convert.ToInt16(away.Attributes["goals"].InnerText); string half_time = halftime.Attributes["score"].InnerText; //format[3-2] char[] del2 = { '-' }; string[] hf = half_time.Substring(1, half_time.Length - 2).Split(del2); int homeGoalsHT = Convert.ToInt16(hf[0]); int awayGoalsHT = Convert.ToInt16(hf[1]); int mtcno = Convert.ToInt32(goalServeMatchID); var mtc = BetDatabase.Matches.Include(x => x.AwayTeam).Include(x => x.HomeTeam).Single(m => m.MatchNo == mtcno); if (mtc == null) { countFail++; continue; } // Match mtc = BetDatabase.Matches.Where(mt => mt.MatchNo == mtcno).SingleOrDefault(); try { mtc.HomeScore = homeGoals; mtc.AwayScore = awayGoals; mtc.HalfTimeAwayScore = awayGoalsHT; mtc.HalfTimeHomeScore = homeGoalsHT; // BetDatabase.Matches.Attach(mtc); BetDatabase.Entry(mtc).State = EntityState.Modified; BetDatabase.SaveChanges(); } catch (DbEntityValidationException ex) { StringBuilder sb = new StringBuilder(); foreach (var failure in ex.EntityValidationErrors) { sb.AppendFormat("{0} failed validation\n", failure.Entry.Entity.GetType()); foreach (var error in failure.ValidationErrors) { sb.AppendFormat("- {0} : {1}", error.PropertyName, error.ErrorMessage); sb.AppendLine(); } } string msg = sb.ToString(); } List <Result> resultList = new List <Result>(); /* Match Results*/ if (mtc.HomeScore > mtc.AwayScore) { Result result = new Result(); result.MatchId = mtc.MatchNo; result.CategoryId = BetDatabase.BetCategories.Where(c => c.CategoryId == 1).FirstOrDefault().CategoryId; result.OptionId = BetDatabase.BetOptions.Where(h => h.BetCategoryId == result.CategoryId).Where(c => c.BetOptionId == 1).FirstOrDefault().BetOptionId; BetDatabase.Results.Add(result); resultList.Add(result); BetDatabase.SaveChanges(); } else if (mtc.HomeScore < mtc.AwayScore) { Result result = new Result(); result.MatchId = mtc.MatchNo; result.CategoryId = BetDatabase.BetCategories.Where(c => c.CategoryId == 1).FirstOrDefault().CategoryId; result.OptionId = BetDatabase.BetOptions.Where(h => h.BetCategoryId == result.CategoryId).Where(c => c.BetOptionId == 3).FirstOrDefault().BetOptionId; BetDatabase.Results.Add(result); resultList.Add(result); BetDatabase.SaveChanges(); } else if (mtc.HomeScore == mtc.AwayScore) { Result result = new Result(); result.MatchId = mtc.MatchNo; result.CategoryId = BetDatabase.BetCategories.Where(c => c.CategoryId == 1).FirstOrDefault().CategoryId; result.OptionId = BetDatabase.BetOptions.Where(h => h.BetCategoryId == result.CategoryId).Where(c => c.BetOptionId == 2).FirstOrDefault().BetOptionId; BetDatabase.Results.Add(result); resultList.Add(result); } /*End Match Result */ /* HaltTime Results*/ if (mtc.HalfTimeHomeScore > mtc.HalfTimeAwayScore) { Result result = new Result(); result.MatchId = mtc.MatchNo; result.CategoryId = BetDatabase.BetCategories.Where(c => c.CategoryId == 3).FirstOrDefault().CategoryId; result.OptionId = BetDatabase.BetOptions.Where(h => h.BetCategoryId == result.CategoryId).Where(c => c.BetOptionId == 12).FirstOrDefault().BetOptionId; BetDatabase.Results.Add(result); resultList.Add(result); BetDatabase.SaveChanges(); } else if (mtc.HalfTimeHomeScore < mtc.HalfTimeAwayScore) { Result result = new Result(); result.MatchId = mtc.MatchNo; result.CategoryId = BetDatabase.BetCategories.Where(c => c.CategoryId == 3).FirstOrDefault().CategoryId; result.OptionId = BetDatabase.BetOptions.Where(h => h.BetCategoryId == result.CategoryId).Where(c => c.BetOptionId == 14).FirstOrDefault().BetOptionId; BetDatabase.Results.Add(result); resultList.Add(result); BetDatabase.SaveChanges(); } else if (mtc.HalfTimeHomeScore == mtc.HalfTimeAwayScore) { Result result = new Result(); result.MatchId = mtc.MatchNo; result.CategoryId = BetDatabase.BetCategories.Where(c => c.CategoryId == 3).FirstOrDefault().CategoryId; result.OptionId = BetDatabase.BetOptions.Where(h => h.BetCategoryId == result.CategoryId).Where(c => c.BetOptionId == 13).FirstOrDefault().BetOptionId; BetDatabase.Results.Add(result); resultList.Add(result); } /*End HalfTime Result */ ///*Start Draw No Bet*/ //if (mtc.HomeScore > mtc.AwayScore) //{ // Result result = new Result(); // result.MatchId = mtc.MatchNo; // result.CategoryId = BetDatabase.BetCategories.Where(c => c.CategoryId == 9).FirstOrDefault().CategoryId; // result.OptionId = BetDatabase.BetOptions.Where(h => h.BetCategoryId == result.CategoryId).Where(c => c.BetOptionId == 13).FirstOrDefault().BetOptionId; // BetDatabase.Results.Add(result); // resultList.Add(result); // BetDatabase.SaveChanges(); //} //else if (mtc.HomeScore < mtc.AwayScore) //{ // Result result = new Result(); // result.MatchId = mtc.MatchNo; // result.CategoryId = BetDatabase.BetCategories.Where(c => c.CategoryId == 9).FirstOrDefault().CategoryId; // result.OptionId = BetDatabase.BetOptions.Where(h => h.BetCategoryId == result.CategoryId).Where(c => c.Option == "DNB2").FirstOrDefault().BetOptionId; // BetDatabase.Results.Add(result); // resultList.Add(result); // BetDatabase.SaveChanges(); //} //else if (mtc.HomeScore == mtc.AwayScore) //{ // Result result = new Result(); // result.MatchId = mtc.MatchNo; // result.CategoryId = BetDatabase.BetCategories.Where(c => c.CategoryId == 9).FirstOrDefault().CategoryId; // result.OptionId = BetDatabase.BetOptions.Where(h => h.BetCategoryId == result.CategoryId).Where(c => c.Option == "DNB2").FirstOrDefault().BetOptionId; // BetDatabase.Results.Add(result); // resultList.Add(result); // BetDatabase.SaveChanges(); //} ///*End Match Result */ /* Start Double Chance*/ if (mtc.HomeScore > mtc.AwayScore) { Result result = new Result(); result.MatchId = mtc.MatchNo; result.CategoryId = BetDatabase.BetCategories.Where(c => c.CategoryId == 9).FirstOrDefault().CategoryId; result.OptionId = BetDatabase.BetOptions.Where(c => c.BetOptionId == 21).FirstOrDefault().BetOptionId; BetDatabase.Results.Add(result); result.OptionId = BetDatabase.BetOptions.Where(c => c.BetOptionId == 22).FirstOrDefault().BetOptionId; BetDatabase.Results.Add(result); resultList.Add(result); } else if (mtc.HomeScore < mtc.AwayScore) { Result result = new Result(); result.MatchId = mtc.MatchNo; result.CategoryId = BetDatabase.BetCategories.Where(c => c.CategoryId == 4).FirstOrDefault().CategoryId; result.OptionId = BetDatabase.BetOptions.Where(c => c.BetOptionId == 23).FirstOrDefault().BetOptionId; BetDatabase.Results.Add(result); result.OptionId = BetDatabase.BetOptions.Where(c => c.BetOptionId == 22).FirstOrDefault().BetOptionId; BetDatabase.Results.Add(result); resultList.Add(result); } else if (mtc.HomeScore == mtc.AwayScore) { Result result = new Result(); result.MatchId = mtc.MatchNo; result.CategoryId = BetDatabase.BetCategories.Where(c => c.CategoryId == 2).FirstOrDefault().CategoryId; result.OptionId = BetDatabase.BetOptions.Where(c => c.BetOptionId == 23).FirstOrDefault().BetOptionId; BetDatabase.Results.Add(result); result.OptionId = BetDatabase.BetOptions.Where(c => c.BetOptionId == 21).FirstOrDefault().BetOptionId; BetDatabase.Results.Add(result); resultList.Add(result); } /*End Double Chance */ /* Start Unders Over*/ /* Full Time Total Goals or Wire or underover*/ int FullTimeTotalGoals = (int)(mtc.HomeScore + mtc.AwayScore); if (FullTimeTotalGoals > 0.5)//over 0.5 { Result result = new Result(); result.MatchId = mtc.MatchNo; result.CategoryId = BetDatabase.BetCategories.Where(c => c.CategoryId == 2).FirstOrDefault().CategoryId; result.OptionId = BetDatabase.BetOptions.Where(c => c.BetOptionId == 33).FirstOrDefault().BetOptionId; BetDatabase.Results.Add(result); resultList.Add(result); } else if (FullTimeTotalGoals < 0.5) //under0.5 { Result result = new Result(); result.MatchId = mtc.MatchNo; result.CategoryId = BetDatabase.BetCategories.Where(c => c.CategoryId == 2).FirstOrDefault().CategoryId; result.OptionId = BetDatabase.BetOptions.Where(c => c.BetOptionId == 32).FirstOrDefault().BetOptionId; BetDatabase.Results.Add(result); BetDatabase.SaveChanges(); resultList.Add(result); } if (FullTimeTotalGoals > 1.5) { Result result = new Result(); result.MatchId = mtc.MatchNo; result.CategoryId = BetDatabase.BetCategories.Where(c => c.CategoryId == 2).FirstOrDefault().CategoryId; result.OptionId = BetDatabase.BetOptions.Where(c => c.BetOptionId == 5).FirstOrDefault().BetOptionId; BetDatabase.Results.Add(result); resultList.Add(result); } else if (FullTimeTotalGoals < 1.5) { Result result = new Result(); result.MatchId = mtc.MatchNo; result.CategoryId = BetDatabase.BetCategories.Where(c => c.CategoryId == 2).FirstOrDefault().CategoryId; result.OptionId = BetDatabase.BetOptions.Where(c => c.BetOptionId == 4).FirstOrDefault().BetOptionId; BetDatabase.Results.Add(result); BetDatabase.SaveChanges(); resultList.Add(result); } if (FullTimeTotalGoals > 2.5) { Result result = new Result(); result.MatchId = mtc.MatchNo; result.CategoryId = BetDatabase.BetCategories.Where(c => c.CategoryId == 2).FirstOrDefault().CategoryId; result.OptionId = BetDatabase.BetOptions.Where(c => c.BetOptionId == 7).FirstOrDefault().BetOptionId; BetDatabase.Results.Add(result); resultList.Add(result); } else if (FullTimeTotalGoals < 2.5) { Result result = new Result(); result.MatchId = mtc.MatchNo; result.CategoryId = BetDatabase.BetCategories.Where(c => c.CategoryId == 2).FirstOrDefault().CategoryId; result.OptionId = BetDatabase.BetOptions.Where(c => c.BetOptionId == 6).FirstOrDefault().BetOptionId; BetDatabase.Results.Add(result); BetDatabase.SaveChanges(); resultList.Add(result); } if (FullTimeTotalGoals > 3.5) { Result result = new Result(); result.MatchId = mtc.MatchNo; result.CategoryId = BetDatabase.BetCategories.Where(c => c.CategoryId == 2).FirstOrDefault().CategoryId; result.OptionId = BetDatabase.BetOptions.Where(c => c.BetOptionId == 9).FirstOrDefault().BetOptionId; BetDatabase.Results.Add(result); resultList.Add(result); } else if (FullTimeTotalGoals < 3.5) { Result result = new Result(); result.MatchId = mtc.MatchNo; result.CategoryId = BetDatabase.BetCategories.Where(c => c.CategoryId == 2).FirstOrDefault().CategoryId; result.OptionId = BetDatabase.BetOptions.Where(c => c.BetOptionId == 8).FirstOrDefault().BetOptionId; BetDatabase.Results.Add(result); BetDatabase.SaveChanges(); resultList.Add(result); } if (FullTimeTotalGoals > 4.5) { Result result = new Result(); result.MatchId = mtc.MatchNo; result.CategoryId = BetDatabase.BetCategories.Where(c => c.CategoryId == 2).FirstOrDefault().CategoryId; result.OptionId = BetDatabase.BetOptions.Where(c => c.BetOptionId == 11).FirstOrDefault().BetOptionId; BetDatabase.Results.Add(result); resultList.Add(result); } else if (FullTimeTotalGoals < 4.5) { Result result = new Result(); result.MatchId = mtc.MatchNo; result.CategoryId = BetDatabase.BetCategories.Where(c => c.CategoryId == 2).FirstOrDefault().CategoryId; result.OptionId = BetDatabase.BetOptions.Where(c => c.BetOptionId == 12).FirstOrDefault().BetOptionId; BetDatabase.Results.Add(result); BetDatabase.SaveChanges(); resultList.Add(result); } if (FullTimeTotalGoals > 5.5) { Result result = new Result(); result.MatchId = mtc.MatchNo; result.CategoryId = BetDatabase.BetCategories.Where(c => c.CategoryId == 2).FirstOrDefault().CategoryId; result.OptionId = BetDatabase.BetOptions.Where(c => c.BetOptionId == 35).FirstOrDefault().BetOptionId; BetDatabase.Results.Add(result); resultList.Add(result); } else if (FullTimeTotalGoals < 5.5) { Result result = new Result(); result.MatchId = mtc.MatchNo; result.CategoryId = BetDatabase.BetCategories.Where(c => c.CategoryId == 2).FirstOrDefault().CategoryId; result.OptionId = BetDatabase.BetOptions.Where(c => c.BetOptionId == 34).FirstOrDefault().BetOptionId; BetDatabase.Results.Add(result); BetDatabase.SaveChanges(); resultList.Add(result); } /*End FullTime U/O/ * * * /*Start HalfTime Unders Over */ /* 0.5 */ int HalfTimeTotalGoals = (int)(mtc.HalfTimeHomeScore + mtc.HalfTimeAwayScore); if (HalfTimeTotalGoals > 0.5) { Result result = new Result(); result.MatchId = mtc.MatchNo; result.CategoryId = BetDatabase.BetCategories.Where(c => c.CategoryId == 4).FirstOrDefault().CategoryId; result.OptionId = BetDatabase.BetOptions.Where(c => c.BetOptionId == 16).FirstOrDefault().BetOptionId; BetDatabase.Results.Add(result); resultList.Add(result); } else if (HalfTimeTotalGoals < 0.5) { Result result = new Result(); result.MatchId = mtc.MatchNo; result.CategoryId = BetDatabase.BetCategories.Where(c => c.CategoryId == 2).FirstOrDefault().CategoryId; result.OptionId = BetDatabase.BetOptions.Where(c => c.BetOptionId == 15).FirstOrDefault().BetOptionId; BetDatabase.Results.Add(result); BetDatabase.SaveChanges(); resultList.Add(result); } /* 0.5*/ /*1.5*/ if (HalfTimeTotalGoals > 1.5) { Result result = new Result(); result.MatchId = mtc.MatchNo; result.CategoryId = BetDatabase.BetCategories.Where(c => c.CategoryId == 4).FirstOrDefault().CategoryId; result.OptionId = BetDatabase.BetOptions.Where(c => c.BetOptionId == 18).FirstOrDefault().BetOptionId; BetDatabase.Results.Add(result); resultList.Add(result); } else if (HalfTimeTotalGoals < 1.5) { Result result = new Result(); result.MatchId = mtc.MatchNo; result.CategoryId = BetDatabase.BetCategories.Where(c => c.CategoryId == 4).FirstOrDefault().CategoryId; result.OptionId = BetDatabase.BetOptions.Where(c => c.BetOptionId == 17).FirstOrDefault().BetOptionId; BetDatabase.Results.Add(result); BetDatabase.SaveChanges(); resultList.Add(result); } /*1.5*/ /*2.5 */ if (HalfTimeTotalGoals > 2.5) { Result result = new Result(); result.MatchId = mtc.MatchNo; result.CategoryId = BetDatabase.BetCategories.Where(c => c.CategoryId == 4).FirstOrDefault().CategoryId; result.OptionId = BetDatabase.BetOptions.Where(c => c.BetOptionId == 20).FirstOrDefault().BetOptionId; BetDatabase.Results.Add(result); resultList.Add(result); } else if (HalfTimeTotalGoals < 2.5) { Result result = new Result(); result.MatchId = mtc.MatchNo; result.CategoryId = BetDatabase.BetCategories.Where(c => c.CategoryId == 4).FirstOrDefault().CategoryId; result.OptionId = BetDatabase.BetOptions.Where(c => c.BetOptionId == 19).FirstOrDefault().BetOptionId; BetDatabase.Results.Add(result); BetDatabase.SaveChanges(); resultList.Add(result); } /* HT2.5*/ /* End 2.5*/ /*End Half Time Unders/Overs * /* Both Teams To Score*/ if ((homeGoals > 0) && (awayGoals > 0)) { Result result = new Result(); result.MatchId = mtc.MatchNo; result.CategoryId = BetDatabase.BetCategories.Where(c => c.CategoryId == 7).FirstOrDefault().CategoryId; result.OptionId = BetDatabase.BetOptions.Where(c => c.BetOptionId == 26).Where(l => l.BetCategoryId == result.CategoryId).FirstOrDefault().BetCategoryId; BetDatabase.Results.Add(result); resultList.Add(result); } else if ((homeGoals == 0) && (awayGoals == 0)) { Result result = new Result(); result.MatchId = mtc.MatchNo; result.CategoryId = BetDatabase.BetCategories.Where(c => c.CategoryId == 7).FirstOrDefault().CategoryId; result.OptionId = BetDatabase.BetOptions.Where(c => c.BetOptionId == 27).Where(l => l.BetCategoryId == result.CategoryId).FirstOrDefault().BetCategoryId; BetDatabase.Results.Add(result); resultList.Add(result); } /*End unders Both Teams To Score*/ foreach (Result score in resultList) { List <Bet> betted = new List <Bet>(); betted = BetDatabase.Bets.Include(f => f.Receipt).Where(s => s.MatchId == score.MatchId).Where(j => j.BetOption.BetCategoryId == score.CategoryId).Where(r => r.GameBetStatus == 0).ToList(); foreach (Bet bm in betted) { Receipt rec = BetDatabase.Receipts.Where(rc => rc.ReceiptId == bm.RecieptId).Where(rc => rc.ReceiptStatus == 1).SingleOrDefault(); if (rec == null) { continue; } rec.SubmitedSize = rec.SubmitedSize + 1; //if (score.OptionId == 30) //{ // betted = BetDatabase.Bets.Where(s => s.MatchId == score.MatchId).Where(j => j.BetOption.BetCategoryId == score.CategoryId).ToList(); // foreach (var bet in betted) // { // Receipt betReciept = BetDatabase.Receipts.Where(rc => rc.ReceiptId == bm.RecieptId).Where(rc => rc.ReceiptStatus == 1).SingleOrDefault(); // Double Divider =Convert.ToDouble( betReciept.TotalOdds); // // betReciept.TotalOdds =Convert.ToDecimal(betReciept.TotalOdds/(Divider)); // } //} if ((bm.BetOptionId == score.OptionId) && (bm.BetOption.BetCategoryId == score.CategoryId)) { rec.WonSize = rec.WonSize + 1; bm.GameBetStatus = 2; } else { rec.ReceiptStatus = 2; bm.GameBetStatus = 1; } BetDatabase.Entry(bm).State = EntityState.Modified; // BetDatabase.Entry(bm).Entity = EntityState.Modified; } } BetDatabase.SaveChanges(); List <Receipt> WonReciepts = new List <Receipt>(); WonReciepts = BetDatabase.Receipts.Where(w => w.SetSize == w.WonSize).Where(s => s.ReceiptStatus == 1).ToList(); if (WonReciepts.Count > 0) { foreach (Receipt wonrec in WonReciepts) { wonrec.ReceiptStatus = 3; } BetDatabase.SaveChanges(); } } catch (Exception e) { string msg = e.Message; countFail++; continue; } } } //end game } //end matches // LbResult.Text = loops.ToString(); } //end category, xml parse try { xmldoc.Load(new MemoryStream()); } catch (Exception ex) { } Thread.Sleep(5000); } var totalTime = (DateTime.Now - start); // }); respond("Success score updates: " + count + "<br />Pending/Failed: " + countFail); } else { respond("<b><font color=\"Red\">Update is already running in the background</font></b>"); } } catch (Exception exception) { } AlreadyRunningUpdate = false; }
public async Task <JsonResult> ReceiveReceipt(Receipt1 receipts) { var bcg = new BarCodeGenerator(); var account = await BetDatabase.Accounts.SingleOrDefaultAsync(x => x.UserId == User.Identity.Name); var branchId = Convert.ToInt32(account.AdminE); var branch = await BetDatabase.Branches.SingleOrDefaultAsync(x => x.BranchId == branchId); var receiptid = bcg.GenerateRandomString(16); var receipt = new Receipt { UserId = User.Identity.Name, BranchId = Convert.ToInt16(account.AdminE), ReceiptStatus = 0, SetNo = 2014927, // ReceiptId = Convert.ToInt32(receiptid) }; //Start New Reciept var betStake = receipts.TotalStake.ToString(CultureInfo.InvariantCulture); string response; BetDatabase.Receipts.Add(receipt); await BetDatabase.SaveChangesAsync(); var ttodd = receipts.TotalOdd; const float bettingLimit = 8000000; var cost = Convert.ToDouble(betStake); if ((cost >= 1000) && (cost <= bettingLimit))//betting limit { foreach (var betData in receipts.BetData) { try { var tempMatchId = Convert.ToInt32(betData.MatchId); var _matchid = BetDatabase.ShortMatchCodes.Single(x => x.ShortCode == tempMatchId).MatchNo; Match _match = BetDatabase.Matches.Single(h => h.MatchNo == _matchid); DateTime _matchTime = _match.StartTime; DateTime timenow = DateTime.Now; if (_matchTime < timenow) { response = ("The Match " + tempMatchId + " Has Started"); return(new JsonResult { Data = new { message = response } }); } var bm = new Bet { BetOptionId = Int32.Parse(betData.OptionId), RecieptId = receipt.ReceiptId, MatchId = BetDatabase.ShortMatchCodes.Single(x => x.ShortCode == tempMatchId).MatchNo, BetOdd = Convert.ToDecimal(betData.Odd), }; BetDatabase.Bets.Add(bm); BetDatabase.SaveChanges(); } catch (Exception er) { response = (" An error has occured:" + er.Message); return(new JsonResult { Data = new { message = response } }); var msg = er.Message; } } // Requires Quick Attention receipt.TotalOdds = Convert.ToDouble(ttodd); receipt.ReceiptStatus = 1; receipt.SetSize = receipts.ReceiptSize; receipt.Stake = cost; receipt.WonSize = 0; receipt.SubmitedSize = 0; receipt.ReceiptDate = DateTime.Now; receipt.Serial = Int2Guid(receiptid); account.DateE = DateTime.Now; // receipt.RecieptID = 34; BetDatabase.Entry(receipt).State = EntityState.Modified; var statement = new Statement { Account = receipt.UserId, Amount = receipt.Stake, Controller = receipt.UserId, StatetmentDate = DateTime.Now, BalBefore = account.AmountE, BalAfter = account.AmountE + receipt.Stake, Comment = "Bet Transaction for Ticket No" + receiptid }; account.AmountE = account.AmountE + receipt.Stake; statement.Transcation = "Teller Bet"; statement.Method = "Online"; statement.Serial = receiptid; branch.Balance = branch.Balance + Convert.ToDecimal(receipt.Stake); BetDatabase.Entry(branch).State = EntityState.Modified; BetDatabase.Accounts.AddOrUpdate(account); BetDatabase.Statements.Add(statement); BetDatabase.SaveChanges(); var barcodeImage = bcg.CreateBarCode(receiptid); var tempPath = Server.MapPath("~/Content/BarCodes/" + receiptid.Trim() + ".png"); try { barcodeImage.Save(tempPath, ImageFormat.Png); } catch (Exception) { } response = ("Success"); } else if (cost < 1000) { receipt.ReceiptId = 0; response = ("Minimum betting stake is UGX 1000. Please enter amount more than UGX 1000."); } else { receipt.ReceiptId = 0; response = ("Maximum stake is UGX " + bettingLimit + ". Please enter amount less than UGX " + bettingLimit + "."); } return(new JsonResult { Data = new { message = response, ReceiptNumber = receipt.ReceiptId, ReceiptTime = String.Format("{0:dd/MM/yyyy}", DateTime.Now) + " - " + toJavaScriptDate(DateTime.Now), TellerName = account.UserId, BranchName = branch.BranchName, Balance = account.AmountE, Serial = receiptid, FormatedSerial = GetSerialNumber(receiptid) } }); }
public int AddScores(MatchScores _match) { int AddedScores = 0; int matchNo = _match.MatchNo; int homeGoals = _match.HomeScore; int awayGoals = _match.AwayScore; int homeGoalsHT = _match.HalfTimeHomeScore; int awayGoalsHT = _match.HalfTimeAwayScore; try { DateTime start = DateTime.Now; string goalServeMatchID = matchNo.ToString(); try { int mtcno = Convert.ToInt32(goalServeMatchID); var mtc = BetDatabase.Matches.Include(x => x.AwayTeam).Include(x => x.HomeTeam).Where(c => c.ResultStatus == 1).Single(m => m.BetServiceMatchNo == mtcno); if (mtc == null) { } // Match mtc = BetDatabase.Matches.Where(mt => mt.BetServiceMatchNo == mtcno).SingleOrDefault(); try { mtc.HomeScore = homeGoals; mtc.AwayScore = awayGoals; mtc.HalfTimeAwayScore = awayGoalsHT; mtc.HalfTimeHomeScore = homeGoalsHT; mtc.ResultStatus = 2; // BetDatabase.Matches.Attach(mtc); BetDatabase.Entry(mtc).State = EntityState.Modified; BetDatabase.SaveChanges(); AddedScores++; } catch (DbEntityValidationException ex) { StringBuilder sb = new StringBuilder(); foreach (var failure in ex.EntityValidationErrors) { sb.AppendFormat("{0} failed validation\n", failure.Entry.Entity.GetType()); foreach (var error in failure.ValidationErrors) { sb.AppendFormat("- {0} : {1}", error.PropertyName, error.ErrorMessage); sb.AppendLine(); } } string msg = sb.ToString(); } List <Result> resultList = new List <Result>(); /* Match Results*/ if (mtc.HomeScore > mtc.AwayScore) { Result result = new Result(); result.MatchId = mtc.BetServiceMatchNo; result.CategoryId = BetDatabase.BetCategories.Where(c => c.CategoryId == 1).FirstOrDefault().CategoryId; result.OptionId = BetDatabase.BetOptions.Where(h => h.BetCategoryId == result.CategoryId).Where(c => c.BetOptionId == 1).FirstOrDefault().BetOptionId; BetDatabase.Results.Add(result); resultList.Add(result); } else if (mtc.HomeScore < mtc.AwayScore) { Result result = new Result(); result.MatchId = mtc.BetServiceMatchNo; result.CategoryId = BetDatabase.BetCategories.Where(c => c.CategoryId == 1).FirstOrDefault().CategoryId; result.OptionId = BetDatabase.BetOptions.Where(h => h.BetCategoryId == result.CategoryId).Where(c => c.BetOptionId == 3).FirstOrDefault().BetOptionId; BetDatabase.Results.Add(result); resultList.Add(result); } else if (mtc.HomeScore == mtc.AwayScore) { Result result = new Result(); result.MatchId = mtc.BetServiceMatchNo; result.CategoryId = BetDatabase.BetCategories.Where(c => c.CategoryId == 1).FirstOrDefault().CategoryId; result.OptionId = BetDatabase.BetOptions.Where(h => h.BetCategoryId == result.CategoryId).Where(c => c.BetOptionId == 2).FirstOrDefault().BetOptionId; BetDatabase.Results.Add(result); resultList.Add(result); } /*End Match Result */ /* HaltTime Results*/ if (mtc.HalfTimeHomeScore > mtc.HalfTimeAwayScore) { Result result = new Result(); result.MatchId = mtc.BetServiceMatchNo; result.CategoryId = BetDatabase.BetCategories.Where(c => c.CategoryId == 3).FirstOrDefault().CategoryId; result.OptionId = BetDatabase.BetOptions.Where(h => h.BetCategoryId == result.CategoryId).Where(c => c.BetOptionId == 12).FirstOrDefault().BetOptionId; BetDatabase.Results.Add(result); resultList.Add(result); } else if (mtc.HalfTimeHomeScore < mtc.HalfTimeAwayScore) { Result result = new Result(); result.MatchId = mtc.BetServiceMatchNo; result.CategoryId = BetDatabase.BetCategories.Where(c => c.CategoryId == 3).FirstOrDefault().CategoryId; result.OptionId = BetDatabase.BetOptions.Where(h => h.BetCategoryId == result.CategoryId).Where(c => c.BetOptionId == 14).FirstOrDefault().BetOptionId; BetDatabase.Results.Add(result); resultList.Add(result); } else if (mtc.HalfTimeHomeScore == mtc.HalfTimeAwayScore) { Result result = new Result(); result.MatchId = mtc.BetServiceMatchNo; result.CategoryId = BetDatabase.BetCategories.Where(c => c.CategoryId == 3).FirstOrDefault().CategoryId; result.OptionId = BetDatabase.BetOptions.Where(h => h.BetCategoryId == result.CategoryId).Where(c => c.BetOptionId == 13).FirstOrDefault().BetOptionId; BetDatabase.Results.Add(result); resultList.Add(result); } /*End HalfTime Result */ ///*Start Draw No Bet*/ //if (mtc.HomeScore > mtc.AwayScore) //{ // Result result = new Result(); // result.MatchId = mtc.BetServiceMatchNo; // result.CategoryId = BetDatabase.BetCategories.Where(c => c.CategoryId == 9).FirstOrDefault().CategoryId; // result.OptionId = BetDatabase.BetOptions.Where(h => h.BetCategoryId == result.CategoryId).Where(c => c.BetOptionId == 13).FirstOrDefault().BetOptionId; // BetDatabase.Results.Add(result); // resultList.Add(result); // BetDatabase.SaveChanges(); //} //else if (mtc.HomeScore < mtc.AwayScore) //{ // Result result = new Result(); // result.MatchId = mtc.BetServiceMatchNo; // result.CategoryId = BetDatabase.BetCategories.Where(c => c.CategoryId == 9).FirstOrDefault().CategoryId; // result.OptionId = BetDatabase.BetOptions.Where(h => h.BetCategoryId == result.CategoryId).Where(c => c.Option == "DNB2").FirstOrDefault().BetOptionId; // BetDatabase.Results.Add(result); // resultList.Add(result); // BetDatabase.SaveChanges(); //} //else if (mtc.HomeScore == mtc.AwayScore) //{ // Result result = new Result(); // result.MatchId = mtc.BetServiceMatchNo; // result.CategoryId = BetDatabase.BetCategories.Where(c => c.CategoryId == 9).FirstOrDefault().CategoryId; // result.OptionId = BetDatabase.BetOptions.Where(h => h.BetCategoryId == result.CategoryId).Where(c => c.Option == "DNB2").FirstOrDefault().BetOptionId; // BetDatabase.Results.Add(result); // resultList.Add(result); // BetDatabase.SaveChanges(); //} ///*End Match Result */ /* Start Double Chance*/ if (mtc.HomeScore > mtc.AwayScore) { Result result = new Result(); result.MatchId = mtc.BetServiceMatchNo; result.CategoryId = BetDatabase.BetCategories.Where(c => c.CategoryId == 9).FirstOrDefault().CategoryId; result.OptionId = BetDatabase.BetOptions.Where(c => c.BetOptionId == 21).FirstOrDefault().BetOptionId; BetDatabase.Results.Add(result); result.OptionId = BetDatabase.BetOptions.Where(c => c.BetOptionId == 22).FirstOrDefault().BetOptionId; BetDatabase.Results.Add(result); resultList.Add(result); } else if (mtc.HomeScore < mtc.AwayScore) { Result result = new Result(); result.MatchId = mtc.BetServiceMatchNo; result.CategoryId = BetDatabase.BetCategories.Where(c => c.CategoryId == 4).FirstOrDefault().CategoryId; result.OptionId = BetDatabase.BetOptions.Where(c => c.BetOptionId == 23).FirstOrDefault().BetOptionId; BetDatabase.Results.Add(result); result.OptionId = BetDatabase.BetOptions.Where(c => c.BetOptionId == 22).FirstOrDefault().BetOptionId; BetDatabase.Results.Add(result); resultList.Add(result); } else if (mtc.HomeScore == mtc.AwayScore) { Result result = new Result(); result.MatchId = mtc.BetServiceMatchNo; result.CategoryId = BetDatabase.BetCategories.Where(c => c.CategoryId == 2).FirstOrDefault().CategoryId; result.OptionId = BetDatabase.BetOptions.Where(c => c.BetOptionId == 23).FirstOrDefault().BetOptionId; BetDatabase.Results.Add(result); result.OptionId = BetDatabase.BetOptions.Where(c => c.BetOptionId == 21).FirstOrDefault().BetOptionId; BetDatabase.Results.Add(result); resultList.Add(result); } /*End Double Chance */ /* Start Unders Over*/ /* Full Time Total Goals or Wire or underover*/ int FullTimeTotalGoals = (int)(mtc.HomeScore + mtc.AwayScore); if (FullTimeTotalGoals > 0.5) //over 0.5 { Result result = new Result(); result.MatchId = mtc.BetServiceMatchNo; result.CategoryId = BetDatabase.BetCategories.Where(c => c.CategoryId == 2).FirstOrDefault().CategoryId; result.OptionId = BetDatabase.BetOptions.Where(c => c.BetOptionId == 33).FirstOrDefault().BetOptionId; BetDatabase.Results.Add(result); resultList.Add(result); } else if (FullTimeTotalGoals < 0.5) //under0.5 { Result result = new Result(); result.MatchId = mtc.BetServiceMatchNo; result.CategoryId = BetDatabase.BetCategories.Where(c => c.CategoryId == 2).FirstOrDefault().CategoryId; result.OptionId = BetDatabase.BetOptions.Where(c => c.BetOptionId == 32).FirstOrDefault().BetOptionId; BetDatabase.Results.Add(result); resultList.Add(result); } if (FullTimeTotalGoals > 1.5) { Result result = new Result(); result.MatchId = mtc.BetServiceMatchNo; result.CategoryId = BetDatabase.BetCategories.Where(c => c.CategoryId == 2).FirstOrDefault().CategoryId; result.OptionId = BetDatabase.BetOptions.Where(c => c.BetOptionId == 5).FirstOrDefault().BetOptionId; BetDatabase.Results.Add(result); resultList.Add(result); } else if (FullTimeTotalGoals < 1.5) { Result result = new Result(); result.MatchId = mtc.BetServiceMatchNo; result.CategoryId = BetDatabase.BetCategories.Where(c => c.CategoryId == 2).FirstOrDefault().CategoryId; result.OptionId = BetDatabase.BetOptions.Where(c => c.BetOptionId == 4).FirstOrDefault().BetOptionId; BetDatabase.Results.Add(result); resultList.Add(result); } if (FullTimeTotalGoals > 2.5) { Result result = new Result(); result.MatchId = mtc.BetServiceMatchNo; result.CategoryId = BetDatabase.BetCategories.Where(c => c.CategoryId == 2).FirstOrDefault().CategoryId; result.OptionId = BetDatabase.BetOptions.Where(c => c.BetOptionId == 7).FirstOrDefault().BetOptionId; BetDatabase.Results.Add(result); resultList.Add(result); } else if (FullTimeTotalGoals < 2.5) { Result result = new Result(); result.MatchId = mtc.BetServiceMatchNo; result.CategoryId = BetDatabase.BetCategories.Where(c => c.CategoryId == 2).FirstOrDefault().CategoryId; result.OptionId = BetDatabase.BetOptions.Where(c => c.BetOptionId == 6).FirstOrDefault().BetOptionId; BetDatabase.Results.Add(result); resultList.Add(result); } if (FullTimeTotalGoals > 3.5) { Result result = new Result(); result.MatchId = mtc.BetServiceMatchNo; result.CategoryId = BetDatabase.BetCategories.Where(c => c.CategoryId == 2).FirstOrDefault().CategoryId; result.OptionId = BetDatabase.BetOptions.Where(c => c.BetOptionId == 9).FirstOrDefault().BetOptionId; BetDatabase.Results.Add(result); resultList.Add(result); } else if (FullTimeTotalGoals < 3.5) { Result result = new Result(); result.MatchId = mtc.BetServiceMatchNo; result.CategoryId = BetDatabase.BetCategories.Where(c => c.CategoryId == 2).FirstOrDefault().CategoryId; result.OptionId = BetDatabase.BetOptions.Where(c => c.BetOptionId == 8).FirstOrDefault().BetOptionId; BetDatabase.Results.Add(result); resultList.Add(result); } if (FullTimeTotalGoals > 4.5) { Result result = new Result(); result.MatchId = mtc.BetServiceMatchNo; result.CategoryId = BetDatabase.BetCategories.Where(c => c.CategoryId == 2).FirstOrDefault().CategoryId; result.OptionId = BetDatabase.BetOptions.Where(c => c.BetOptionId == 11).FirstOrDefault().BetOptionId; BetDatabase.Results.Add(result); resultList.Add(result); } else if (FullTimeTotalGoals < 4.5) { Result result = new Result(); result.MatchId = mtc.BetServiceMatchNo; result.CategoryId = BetDatabase.BetCategories.Where(c => c.CategoryId == 2).FirstOrDefault().CategoryId; result.OptionId = BetDatabase.BetOptions.Where(c => c.BetOptionId == 12).FirstOrDefault().BetOptionId; BetDatabase.Results.Add(result); resultList.Add(result); } if (FullTimeTotalGoals > 5.5) { Result result = new Result(); result.MatchId = mtc.BetServiceMatchNo; result.CategoryId = BetDatabase.BetCategories.Where(c => c.CategoryId == 2).FirstOrDefault().CategoryId; result.OptionId = BetDatabase.BetOptions.Where(c => c.BetOptionId == 35).FirstOrDefault().BetOptionId; BetDatabase.Results.Add(result); resultList.Add(result); } else if (FullTimeTotalGoals < 5.5) { Result result = new Result(); result.MatchId = mtc.BetServiceMatchNo; result.CategoryId = BetDatabase.BetCategories.Where(c => c.CategoryId == 2).FirstOrDefault().CategoryId; result.OptionId = BetDatabase.BetOptions.Where(c => c.BetOptionId == 34).FirstOrDefault().BetOptionId; BetDatabase.Results.Add(result); resultList.Add(result); } /*End FullTime U/O/ * * * /*Start HalfTime Unders Over */ /* 0.5 */ int HalfTimeTotalGoals = (int)(mtc.HalfTimeHomeScore + mtc.HalfTimeAwayScore); if (HalfTimeTotalGoals > 0.5) { Result result = new Result(); result.MatchId = mtc.BetServiceMatchNo; result.CategoryId = BetDatabase.BetCategories.Where(c => c.CategoryId == 4).FirstOrDefault().CategoryId; result.OptionId = BetDatabase.BetOptions.Where(c => c.BetOptionId == 16).FirstOrDefault().BetOptionId; BetDatabase.Results.Add(result); resultList.Add(result); } else if (HalfTimeTotalGoals < 0.5) { Result result = new Result(); result.MatchId = mtc.BetServiceMatchNo; result.CategoryId = BetDatabase.BetCategories.Where(c => c.CategoryId == 2).FirstOrDefault().CategoryId; result.OptionId = BetDatabase.BetOptions.Where(c => c.BetOptionId == 15).FirstOrDefault().BetOptionId; BetDatabase.Results.Add(result); resultList.Add(result); } /* 0.5*/ /*1.5*/ if (HalfTimeTotalGoals > 1.5) { Result result = new Result(); result.MatchId = mtc.BetServiceMatchNo; result.CategoryId = BetDatabase.BetCategories.Where(c => c.CategoryId == 4).FirstOrDefault().CategoryId; result.OptionId = BetDatabase.BetOptions.Where(c => c.BetOptionId == 18).FirstOrDefault().BetOptionId; BetDatabase.Results.Add(result); resultList.Add(result); } else if (HalfTimeTotalGoals < 1.5) { Result result = new Result(); result.MatchId = mtc.BetServiceMatchNo; result.CategoryId = BetDatabase.BetCategories.Where(c => c.CategoryId == 4).FirstOrDefault().CategoryId; result.OptionId = BetDatabase.BetOptions.Where(c => c.BetOptionId == 17).FirstOrDefault().BetOptionId; BetDatabase.Results.Add(result); BetDatabase.SaveChanges(); resultList.Add(result); } /*1.5*/ /*2.5 */ if (HalfTimeTotalGoals > 2.5) { Result result = new Result(); result.MatchId = mtc.BetServiceMatchNo; result.CategoryId = BetDatabase.BetCategories.Where(c => c.CategoryId == 4).FirstOrDefault().CategoryId; result.OptionId = BetDatabase.BetOptions.Where(c => c.BetOptionId == 20).FirstOrDefault().BetOptionId; BetDatabase.Results.Add(result); resultList.Add(result); } else if (HalfTimeTotalGoals < 2.5) { Result result = new Result(); result.MatchId = mtc.BetServiceMatchNo; result.CategoryId = BetDatabase.BetCategories.Where(c => c.CategoryId == 4).FirstOrDefault().CategoryId; result.OptionId = BetDatabase.BetOptions.Where(c => c.BetOptionId == 19).FirstOrDefault().BetOptionId; BetDatabase.Results.Add(result); resultList.Add(result); } /* HT2.5*/ /* End 2.5*/ /*End Half Time Unders/Overs * /* Both Teams To Score*/ if ((homeGoals > 0) && (awayGoals > 0)) { Result result = new Result(); result.MatchId = mtc.BetServiceMatchNo; result.CategoryId = BetDatabase.BetCategories.Where(c => c.CategoryId == 7).FirstOrDefault().CategoryId; result.OptionId = BetDatabase.BetOptions.Where(c => c.BetOptionId == 26).Where(l => l.BetCategoryId == result.CategoryId).FirstOrDefault().BetCategoryId; BetDatabase.Results.Add(result); resultList.Add(result); } else if ((homeGoals == 0) && (awayGoals == 0)) { Result result = new Result(); result.MatchId = mtc.BetServiceMatchNo; result.CategoryId = BetDatabase.BetCategories.Where(c => c.CategoryId == 7).FirstOrDefault().CategoryId; result.OptionId = BetDatabase.BetOptions.Where(c => c.BetOptionId == 27).Where(l => l.BetCategoryId == result.CategoryId).FirstOrDefault().BetCategoryId; BetDatabase.Results.Add(result); resultList.Add(result); } /*End unders Both Teams To Score*/ foreach (Result score in resultList) { List <Bet> betted = new List <Bet>(); betted = BetDatabase.Bets.Include(f => f.Receipt).Where(s => s.MatchId == score.MatchId).Where(j => j.BetOption.BetCategoryId == score.CategoryId).Where(r => r.GameBetStatus == 0).ToList(); foreach (Bet bm in betted) { Receipt rec = BetDatabase.Receipts.Where(rc => rc.ReceiptId == bm.RecieptId).Where(rc => rc.ReceiptStatus == 1).SingleOrDefault(); if (rec == null) { continue; } rec.SubmitedSize = rec.SubmitedSize + 1; if ((bm.BetOptionId == score.OptionId) && (bm.BetOption.BetCategoryId == score.CategoryId)) { rec.WonSize = rec.WonSize + 1; bm.GameBetStatus = 2; } else if ((score.CategoryId == 2) || (score.CategoryId == 4)) { int subCategory = getSubCategory(score.OptionId); int baseCategory = getSubCategory(bm.BetOptionId); if (UnderOverCat(subCategory, baseCategory)) { rec.ReceiptStatus = 2; bm.GameBetStatus = 1; } else { continue; } } else { rec.ReceiptStatus = 2; bm.GameBetStatus = 1; } BetDatabase.Entry(bm).State = EntityState.Modified; // BetDatabase.Entry(bm).Entity = EntityState.Modified; } } BetDatabase.SaveChanges(); List <Receipt> WonReciepts = new List <Receipt>(); WonReciepts = BetDatabase.Receipts.Where(w => w.SetSize == w.WonSize).Where(s => s.ReceiptStatus == 1).ToList(); if (WonReciepts.Count > 0) { foreach (Receipt wonrec in WonReciepts) { wonrec.ReceiptStatus = 3; } BetDatabase.SaveChanges(); } } catch (Exception e) { string msg = e.Message; } } catch (Exception exception) { } return(AddedScores); }