public void UserBetWin() { var userId = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier)?.Value; var user = _context.Users.FirstOrDefault(u => u.Id == userId); foreach (var item in _context.UserBetMatch.Where(u => u.UserBet.User.Id == userId && u.Win == "Pending") .Include(m => m.Match.HomeTeam) .Include(a => a.Match.AwayTeam) .Include(u => u.UserBet).ToList()) { var match = _context.Result.Where(m => m.Id == item.Match.Id).FirstOrDefault(); if (match != null) { var winningTypes = match.WinningTypes.Split(';'); foreach (var type in winningTypes) { if (item.Type == type) { item.Win = "Win"; } } if (item.Win == "Pending") { item.Win = "Lose"; } item.Result = match.Result; _context.Update(item); _context.SaveChanges(); } } CheckTicket(user); }
public async Task ImportTwoPlayerDatabase() { string path = @"C:\Users\antee\Documents\Visual Studio 2019\Projects\BettingApplication\MatchesImportTwoPlayer.csv"; using (var reader = new StreamReader(path)) { while (!reader.EndOfStream) { var line = reader.ReadLine(); var values = line.Split(';'); var match = new MatchViewModel(); var sportTennis = _context.Sport.SingleOrDefault(s => s.Name.Contains("Tenis")); var leagueATP = _context.League.SingleOrDefault(l => l.Name.Contains("ATP")); var hour = values[4].Split(':'); var firstTeam = values[0].Split('"'); _context.Match.AddRange( new Match { HomeTeam = new Team { Name = firstTeam[1], League = leagueATP }, AwayTeam = new Team { Name = values[1], League = leagueATP }, Type = new Type { _1 = Convert.ToDecimal(values[2]), _2 = Convert.ToDecimal(values[3]) }, Time = new DateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, DateTime.UtcNow.Day, Int32.Parse(hour[0]), Int32.Parse(hour[1]), 00), Sport = sportTennis, }); _context.SaveChanges(); } } }
public async Task <List <ResultModel> > GetResults() { //string[] allowedSport = new string[] { "Football", "TENIS", "Hokej", "Košarka", "Rukomet" }; //string[] allowedFootballLeague = new string[] // {"ŠPANJOLSKA", "ITALIJA", "FRANCUSKA", "ENGLESKA", "NJEMAČKA"}; var date = DateTime.Now; string url = $"https://sportdataprovider.volcanobet.me/api/public/Results/getResultOverviews?date={date.Year}-{date.Month.ToString("00")}-{date.Day}T00:00:00.000Z&sportId=1&clientType=WebConsumer&v=1.1.435&lang=sr-Latn-EN"; //string url = "https://sportdataprovider.volcanobet.me/api/public/Results/getDailyResultOverviews?sportId=1&clientType=WebConsumer&v=1.1.496-rc6&lang=sr-Latn-ME"; string html; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.AutomaticDecompression = DecompressionMethods.GZip; using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) using (Stream stream = response.GetResponseStream()) using (StreamReader reader = new StreamReader(stream)) { html = reader.ReadToEnd(); } var results = JsonConvert.DeserializeObject <List <ResultsModel> >(html); var convertedResult = new List <ResultModel>(); foreach (var result in results.Where(t => t.Scores.Count > 0)) { var match = await _context.Result.Where(t => t.Id == result.Fixture.EventId).FirstOrDefaultAsync(); if (match == null) { var r = new ResultModel(); r.Id = result.Fixture.EventId; r.SportName = result.Fixture.Sport.Name; r.LeagueName = $"{result.Fixture.League.LocationName} - {result.Fixture.League.Name}"; r.Time = result.Fixture.StartDate.AddHours(1); r.HomeTeam = result.Fixture.Participants[0].Name; r.AwayTeam = result.Fixture.Participants[1].Name; r.WinningTypes = CalculateWinningTypes(Int32.Parse(result.Scores[0].Value), Int32.Parse(result.Scores[1].Value)); r.Result = $"{result.Scores[0].Value}:{result.Scores[1].Value}"; _context.AddRange(r); _context.SaveChanges(); convertedResult.Add(r); } } return(convertedResult); }
public async Task CheckTicket(AppUser user) { bool flag = false; string pendingFlag = ""; var check = await _context.UserBet.Where(x => x.User.Id == user.Id).FirstOrDefaultAsync(); var userBets = _context.UserBet.Where(t => t.Win == "Pending" && t.User == user).Include(x => x.BetMatches).ToList(); if (check != null) { if (userBets.Count > 0) { { foreach (var item in userBets) { pendingFlag = null; foreach (var match in item.BetMatches) { if (match.Win == "Lose") { item.Win = "Lose"; _context.Update(item); _context.SaveChanges(); break; } else if (match.Win == "Win") { flag = true; } else if (match.Win == "Pending") { pendingFlag = "Pending"; } } if (flag == true && String.IsNullOrEmpty(pendingFlag)) { item.Win = "Win"; _context.Update(item); var wallet = await _context.Wallet.Where(u => u.User.Id == user.Id).FirstOrDefaultAsync(); wallet.Saldo += item.CashOut; UserTransaction transaction = new UserTransaction(); transaction.UserId = wallet.User.Id; transaction.Payment = item.CashOut.ToString(); transaction.Transactions = "Isplata dobitka u iznosu od " + item.CashOut + " kn " + " " + DateTime.Now.ToString(); _context.Update(wallet); _context.Update(transaction); await _context.SaveChangesAsync(); } } } } } }
public IActionResult Add(string name, string sport) { var sportName = _context.Sport.Where(s => s.Name == sport).FirstOrDefault(); var league = new League(); league.Name = name; league.Sport = sportName; _context.League.Add(league); _context.SaveChanges(); return(RedirectToAction("Add", "Matches")); }
public static void InitializeAsync(IServiceProvider serviceProvider) { using (var context = new BettingApplicationContext( serviceProvider.GetRequiredService < DbContextOptions <BettingApplicationContext> >())) { if (context.AdminTopMatchConfig.Any()) { return; // DB has been seeded } context.AdminTopMatchConfig.AddRange( new AdminTopMatchConfig { MinimumNumberOfMatches = 5 }); context.SaveChanges(); } }
public async Task <IActionResult> DeleteUserConfirmed(string id) { if (!String.IsNullOrEmpty(id)) { await _accountService.DeleteUser(id); var user = _context.Wallet.Where(u => u.User.Id == id).FirstOrDefault();//TODO _context.Wallet.Remove(user); _context.SaveChanges(); AppUser applicationUser = await _userManager.FindByIdAsync(id); if (applicationUser != null) { IdentityResult result = await _userManager.DeleteAsync(applicationUser); if (result.Succeeded) { return(RedirectToAction("UsersList")); } } } return(View()); }
public async Task GenerateOffer() { var date = DateTime.Now; var yesterday = date.AddDays(-1).ToString("yyyy-MM-dd"); var tommorow = date.AddDays(1).ToString("yyyy-MM-dd"); string url = $"https://sportdataprovider.volcanobet.me/api/public/prematch/SportEvents?SportId=1&from={yesterday}T23:00:00.000Z&to={tommorow}T06:00:00.000Z&timezone=-60&clientType=WebConsumer&v=1.1.496-rc6&lang=sr-Latn-EN"; string html; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.AutomaticDecompression = DecompressionMethods.GZip; using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) using (Stream stream = response.GetResponseStream()) using (StreamReader reader = new StreamReader(stream)) { html = reader.ReadToEnd(); } var offer = JsonConvert.DeserializeObject <OfferModel>(html); var sport = await _context.Sport.Where(s => s.Name == offer.Sport.Name).FirstOrDefaultAsync(); if (sport == null) { sport = new Sport(); sport.Name = offer.Sport.Name; _context.AddRange(sport); _context.SaveChanges(); } foreach (var location in offer.Locations) { foreach (var league in location.Leagues) { var leagueDatabase = await _context.League.Where(l => l.Name == $"{location.Name} - {league.Name}") .SingleOrDefaultAsync(); if (leagueDatabase == null) { leagueDatabase = new League(); leagueDatabase.Name = $"{location.Name} - {league.Name}"; leagueDatabase.Sport = sport; _context.League.AddRange(leagueDatabase); _context.SaveChanges(); } foreach (var eventDate in league.EventDateGroups) { foreach (var eventDateEvent in eventDate.Events) { var matchModel = new Match(); matchModel.Competition = league.Name; matchModel.Id = eventDateEvent.Id; var types = new Type(); matchModel.Sport = sport; matchModel.Time = eventDateEvent.Fixture.StartDate.AddHours(1); var firstTeam = await _context.Team .Where(t => t.Name == eventDateEvent.Fixture.Participants[0].Name) .FirstOrDefaultAsync(); var secondTeam = await _context.Team .Where(t => t.Name == eventDateEvent.Fixture.Participants[1].Name) .FirstOrDefaultAsync(); if (firstTeam == null) { firstTeam = new Team(); firstTeam.League = leagueDatabase; firstTeam.Name = eventDateEvent.Fixture.Participants[0].Name; _context.Team.AddRange(firstTeam); matchModel.HomeTeam = firstTeam; } if (firstTeam != null) { matchModel.HomeTeam = firstTeam; } if (secondTeam == null) { secondTeam = new Team(); secondTeam.League = leagueDatabase; secondTeam.Name = eventDateEvent.Fixture.Participants[1].Name; _context.Team.AddRange(secondTeam); matchModel.AwayTeam = secondTeam; } if (secondTeam != null) { matchModel.AwayTeam = secondTeam; } foreach (var market in eventDateEvent.Markets) { if (market.Name == "1x2") { foreach (var pick in market.Picks) { if (pick.Name == "1") { types._1 = pick.Odds; } if (pick.Name == "x") { types._X = pick.Odds; } if (pick.Name == "2") { types._2 = pick.Odds; } } } if (market.Name == "Double chance") { foreach (var pick in market.Picks) { if (pick.Name == "1x") { types._1X = pick.Odds; } if (pick.Name == "x2") { types._X2 = pick.Odds; } if (pick.Name == "12") { types._12 = pick.Odds; } } } } var matchExist = await _context.Match .Include(h => h.HomeTeam) .Include(a => a.AwayTeam) .Where(m => m.HomeTeam == matchModel.HomeTeam && m.AwayTeam == matchModel.AwayTeam && m.Time == matchModel.Time).FirstOrDefaultAsync(); if (matchExist == null && matchModel.HomeTeam != null && matchModel.AwayTeam != null) { matchModel.Type = types; matchModel.TopMatch = false; matchModel.Hide = false; _context.Match.Add(matchModel); _context.SaveChanges(); } } } } } }
public async Task <IActionResult> ImportDatabase() { string path = @"C:\Users\antee\Documents\Visual Studio 2019\Projects\BettingApplication\MatchesImport.csv"; using (var reader = new StreamReader(path)) { while (!reader.EndOfStream) { try { var line = reader.ReadLine(); var values = line.Split(';'); var match = new MatchViewModel(); var sportFootball = _context.Sport.SingleOrDefault(s => s.Name.Contains("Football")); var hour = values[8].Split(':'); var firstTeam = values[0].Split('"'); var secondTeam = values[1]; var time = new DateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, DateTime.UtcNow.Day, Int32.Parse(hour[0]), Int32.Parse(hour[1]), 00); var HomeTeam = _context.Team.FirstOrDefault(s => s.Name.Contains(firstTeam[1])); var AwayTeam = _context.Team.FirstOrDefault(s => s.Name.Contains(values[1])); if (HomeTeam == null || AwayTeam == null) { ModelState.AddModelError("Error", $"Wrong name: {firstTeam[1]} or {values[1]}"); return(View()); } var Time = new DateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, DateTime.UtcNow.Day, Int32.Parse(hour[0]), Int32.Parse(hour[1]), 00); var Types = new Type { _1 = Convert.ToDecimal(values[2]), _X = Convert.ToDecimal(values[3]), _2 = Convert.ToDecimal(values[4]), _1X = Convert.ToDecimal(values[5]), _X2 = Convert.ToDecimal(values[6]), _12 = Convert.ToDecimal(values[7]) }; var Sport = sportFootball; if ((await _context.Match.Where(t => t.HomeTeam.Name == firstTeam[1] && t.AwayTeam.Name == secondTeam && t.Time == time).FirstOrDefaultAsync()) == null) { _context.Match.AddRange( new Match { HomeTeam = _context.Team.First(s => s.Name.Contains(firstTeam[1])), AwayTeam = _context.Team.First(s => s.Name.Contains(values[1])), Time = new DateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, DateTime.UtcNow.Day, Int32.Parse(hour[0]), Int32.Parse(hour[1]), 00), Type = new Type { _1 = Convert.ToDecimal(values[2]), _X = Convert.ToDecimal(values[3]), _2 = Convert.ToDecimal(values[4]), _1X = Convert.ToDecimal(values[5]), _X2 = Convert.ToDecimal(values[6]), _12 = Convert.ToDecimal(values[7]) }, Sport = sportFootball }); _context.SaveChanges(); } } catch (Exception e) { ModelState.AddModelError("Error", $"{e}"); return(View()); } } return(View()); } }