public bool CreateLeague(LeagueCreate model) { var entity = new LeagueEntity { LeagueName = model.LeagueName, OwnerID = _userID }; int changeCount = 1; if (model.Teams != null) { entity.Teams = new List <TeamEntity>(); foreach (LeagueTeamCreate team in model.Teams) { entity.Teams.Add( new TeamEntity { OwnerID = _userID, TeamName = team.TeamName, ImageData = team.ImageData }); } changeCount += entity.Teams.Count; } using (var ctx = new ApplicationDbContext()) { ctx.Leagues.Add(entity); return(ctx.SaveChanges() == changeCount); } }
private async Task CheckTeamsAsync() { LeagueEntity league1 = _context.Leagues.FirstOrDefault(t => t.Name == "Superliga Argentina"); LeagueEntity league2 = _context.Leagues.FirstOrDefault(t => t.Name == "Conmebol"); LeagueEntity league3 = _context.Leagues.FirstOrDefault(t => t.Name == "Liga Aguila"); if (!_context.Teams.Any()) { AddTeam("Aldosivi", "ALD", league1); AddTeam("Argentinos Juniors", "ARJ", league1); AddTeam("Arsenal", "ARS", league1); AddTeam("Atlético Tucumán", "ATL ", league1); AddTeam("Banfield", "BAN", league1); AddTeam("Boca Juniors", "BOC", league1); AddTeam("Central Córdoba", "CCA", league1); AddTeam("Colón", "COL", league1); AddTeam("Defensa y Justicia", "DYJ", league1); AddTeam("Estudiantes", "EST", league1); AddTeam("Gimnasia", "GIM", league1); AddTeam("Godoy Cruz", "GOD", league1); AddTeam("Huracán", "HUR", league1); AddTeam("Independiente", "IND", league1); AddTeam("Lanús", "LAN", league1); AddTeam("Newells", "NEW", league1); AddTeam("Patronato", "PAT", league1); AddTeam("Racing", "RAC", league1); AddTeam("River Plate", "RIV", league1); AddTeam("Rosario Central", "ROS", league1); AddTeam("San Lorenzo", "SLO", league1); AddTeam("Talleres", "TAL", league1); AddTeam("Union", "UNI", league1); AddTeam("Velez Sarsfield", "VEL", league1); AddTeam("Argentina", "ARG", league2); AddTeam("Bolivia", "BOL", league2); AddTeam("Brasil", "BRA", league2); AddTeam("Chile", "CHI", league2); AddTeam("Colombia", "COL", league2); AddTeam("Ecuador", "ECU", league2); AddTeam("Paraguay", "PAR", league2); AddTeam("Peru", "PER", league2); AddTeam("Uruguay", "URU", league2); AddTeam("Venezuela", "VEN", league2); AddTeam("America", "AME", league3); AddTeam("Bucaramanga", "BUC", league3); AddTeam("Junior", "JUN", league3); AddTeam("Medellin", "MED", league3); AddTeam("Millonarios", "MIL", league3); AddTeam("Nacional", "NAC", league3); AddTeam("Once Caldas", "ONC", league3); AddTeam("Santa Fe", "SFE", league3); await _context.SaveChangesAsync(); } }
public LeagueViewModel ToLeagueViewModel(LeagueEntity leagueEntity) { return(new LeagueViewModel { Id = leagueEntity.Id, LogoPath = leagueEntity.LogoPath, Name = leagueEntity.Name }); }
private static Queue <TeamStatisticsModel> SortOutLeagueTeams(LeagueEntity league) { var statistics = GenerateLeagueTeamsStatistics(league); var queue = new Queue <TeamStatisticsModel>(statistics); SetTablePositions(queue); return(queue); }
public bool SubmitLeagueIfNotDuplicate(LeagueEntity league) { if (!leagueAlreadyExists(league)) { context.Add(league); context.SaveChanges(); return(true); } return(false); }
public static LeagueEntity GetLeague(LeaguePosition leaguePosition) { LeagueEntity result = new LeagueEntity(); result.LeagueId = leaguePosition.leagueId; result.Name = leaguePosition.leagueName; result.Queue = leaguePosition.queueType; result.Tier = leaguePosition.tier; return(result); }
public LeagueResponse ToLeagueResponse(LeagueEntity leagueEntity) { return(new LeagueResponse { Id = leagueEntity.Id, Name = leagueEntity.Name, Teams = leagueEntity.Teams?.Select(g => new TeamResponse { Id = g.Id, Name = g.Name, Initials = g.Initials, LogoPath = g.LogoPath, LeagueId = g.League.Id, LeagueName = g.League.Name }).ToList(), }); }
// GET: Leagues/Edit/5 public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } LeagueEntity leagueEntity = await _context.Leagues.FindAsync(id); if (leagueEntity == null) { return(NotFound()); } LeagueViewModel model = _converterHelper.ToLeagueViewModel(leagueEntity); return(View(model)); }
public ICollection <BetRatesEntity> GetLeagueGamesRates(LeagueEntity league) { var leagueTable = LeagueTableModel.Factory.NewLeagueTable(league); var betRates = new ConcurrentBag <BetRatesEntity>(); Parallel.ForEach(league.Games.GetEmptyIfNull(), game => { var homeTeam = leagueTable.Table.SingleOrDefault(t => t.TeamId == game.HomeTeamId); var awayTeam = leagueTable.Table.SingleOrDefault(t => t.TeamId == game.AwayTeamId); var rates = GetGameRates(homeTeam, awayTeam, league.Teams.Count); rates.GameId = game.GameId; betRates.Add(rates); }); return(betRates.ToList()); }
public async Task CreateLeague(League league, int initialYear, LeagueOptions options) { LeagueEntity entity = new LeagueEntity(league); LeagueYearEntity leagueYearEntity = new LeagueYearEntity(league, initialYear, options, PlayStatus.NotStartedDraft); using (var connection = new MySqlConnection(_connectionString)) { await connection.ExecuteAsync( "insert into tblleague(LeagueID,LeagueName,LeagueManager) VALUES " + "(@LeagueID,@LeagueName,@LeagueManager);", entity); await connection.ExecuteAsync( "insert into tblleagueyear(LeagueID,Year,StandardGames,GamesToDraft,CounterPicks,MaximumEligibilityLevel,AllowYearlyInstallments,AllowEarlyAccess,DraftSystem,PickupSystem,ScoringSystem,PlayStatus) VALUES " + "(@LeagueID,@Year,@StandardGames,@GamesToDraft,@CounterPicks,@MaximumEligibilityLevel,@AllowYearlyInstallments,@AllowEarlyAccess,@DraftSystem,@PickupSystem,@ScoringSystem,@PlayStatus);", leagueYearEntity); } await AddPlayerToLeague(league, league.LeagueManager); }
public async Task <Maybe <League> > GetLeagueByID(Guid id) { using (var connection = new MySqlConnection(_connectionString)) { var queryObject = new { leagueID = id }; LeagueEntity leagueEntity = await connection.QuerySingleAsync <LeagueEntity>( "select * from tblleague where LeagueID = @leagueID", queryObject); FantasyCriticUser manager = await _userStore.FindByIdAsync(leagueEntity.LeagueManager.ToString(), CancellationToken.None); IEnumerable <LeagueYearEntity> yearEntities = await connection.QueryAsync <LeagueYearEntity>("select * from tblleagueyear where LeagueID = @leagueID", queryObject); IEnumerable <int> years = yearEntities.Select(x => x.Year); League league = leagueEntity.ToDomain(manager, years); return(league); } }
//collect league information from summonerEntities. public void CollectLeagueNames(IEnumerable <SummonerEntity> summonerEntities) { int summonersQueried = 0; int leaguesFound = 0; foreach (SummonerEntity summoner in summonerEntities) { IEnumerable <LeaguePosition> leaguesList = new ApiRequest(requestStringHolder).League.LeaguePositions(summoner.SummonerId); if (leaguesList != null) { IEnumerable <LeaguePosition> soloQLeague = leaguesList.Where(x => x.queueType == "RANKED_SOLO_5x5"); LeaguePosition leaguePos = soloQLeague.FirstOrDefault(); LeagueEntity league = EntityFromRiotDto.GetLeague(leaguePos); if (league != null && dbHelper.SubmitLeagueIfNotDuplicate(league)) { leaguesFound++; } } summonersQueried++; Console.Clear(); Console.WriteLine($"{summonersQueried} Summoners From {leaguesFound} Leagues"); } }
public async Task <IActionResult> Edit(LeagueViewModel model) { if (ModelState.IsValid) { if (ModelState.IsValid) { var path = model.LogoPath; if (model.LogoFile != null) { path = await _imageHelper.UploadImageAsync(model.LogoFile, "Leagues"); } LeagueEntity league = _converterHelper.ToLeagueEntity(model, path, false); _context.Update(league); try { await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } catch (Exception ex) { if (ex.InnerException.Message.Contains("duplicate")) { ModelState.AddModelError(string.Empty, "Esta Liga ya existe"); } else { ModelState.AddModelError(string.Empty, ex.InnerException.Message); } } } } return(View(model)); }
private static IEnumerable <TeamStatisticsModel> GenerateLeagueTeamsStatistics(LeagueEntity league) { return((from team in league.Teams let teamHomeGames = league.Games.Where(g => g.HomeTeamId == team.TeamId) let teamAwayGames = league.Games.Where(g => g.AwayTeamId == team.TeamId) let homeGamesWon = teamHomeGames.Count(g => g.GoalsHomeTeam > g.GoalsAwayTeam) let homeGamesLost = teamHomeGames.Count(g => g.GoalsHomeTeam < g.GoalsAwayTeam) let homeGamesTied = teamHomeGames.Count(g => g.GoalsHomeTeam == g.GoalsAwayTeam) let awayGamesWon = teamAwayGames.Count(g => g.GoalsHomeTeam < g.GoalsAwayTeam) let awayGamesLost = teamAwayGames.Count(g => g.GoalsHomeTeam > g.GoalsAwayTeam) let awayGamesTied = teamAwayGames.Count(g => g.GoalsHomeTeam == g.GoalsAwayTeam) let goalsScored = teamHomeGames.Sum(t => t.GoalsHomeTeam) + teamAwayGames.Sum(t => t.GoalsAwayTeam) let goalsLost = teamHomeGames.Sum(t => t.GoalsAwayTeam) + teamAwayGames.Sum(t => t.GoalsHomeTeam) let points = (homeGamesWon + awayGamesWon) * GameConstants.WonGamePointsAmount + (homeGamesTied + awayGamesTied) * GameConstants.TiedGamePointsAmount select new TeamStatisticsModel { TeamId = team.TeamId, TeamName = team.Name, Points = points, GoalsScored = goalsScored, GoalsLost = goalsLost, WonGamesAmount = homeGamesWon + awayGamesWon, TiedMatchesAmount = homeGamesTied + awayGamesTied, LostGamesAmount = homeGamesLost + awayGamesLost }) .OrderByDescending(t => t.Points) .ToList()); }
private void AddTeam(string name, string initials, LeagueEntity league) { _context.Teams.Add(new TeamEntity { Name = name, Initials = initials, League = league, LogoPath = $"~/images/Teams/{name}.jpg" }); }
public static LeagueTableModel NewLeagueTable(LeagueEntity league) { var table = SortOutLeagueTeams(league); return(new LeagueTableModel(league.LeagueId, league.Name, table)); }
//returns true if league already exists in db. private bool leagueAlreadyExists(LeagueEntity league) { var queryResult = context.Leagues.Where(x => x.LeagueId == league.LeagueId).SingleOrDefault(); return(queryResult != null); }
public void Process(BaseData data) { BRData bd = data as BRData; string txt; if (!HtmlDecode(bd.Html, out txt)) { return; } var xml = new XmlHelper(txt); var cdataFlag = "//c"; var cdata = xml.GetValue(cdataFlag); if (string.IsNullOrEmpty(cdata)) { return; } var root = GetHtmlRoot(cdata); var jd2 = root.SelectSingleNode("//li[@class='topelem sport-1']/ul[@class=' jdlvl_2']"); List <HtmlNode> needNodes = new List <HtmlNode>(); foreach (var c2 in jd2.ChildNodes) { needNodes.Clear(); var cs = c2.ChildNodes[0]; var cc = cs.Attributes["href"]; // 大洲的信息 string continentId; string continentName; if (cc == null) { continentId = "7"; continentName = cs.InnerText; } else { continentId = RegexGetStr(cs.Attributes["href"].Value, "22_", "',"); continentName = cs.InnerText; } var jd3 = c2.SelectSingleNode("ul[contains(@class,'jdlvl_3')]"); if (jd3 == null) { continue; } #region 国际,俱乐部 // 处理国际和俱乐部组织的联赛 Dictionary <string, List <string> > dic = new Dictionary <string, List <string> >() { { "4", new List <string>() }, { "393", new List <string>() } }; for (int i = 0; i < jd3.ChildNodes.Count; i++) { if (i % 3 == 2) { // 第二列国际 var n2 = jd3.ChildNodes[i - 1]; // 第三列俱乐部 var n3 = jd3.ChildNodes[i]; OrganizerEntity oe; if (i == 2) // 标题行的处理 { var key = "393"; oe = OrganizerEntityManager.AddOrGetCacheEntity <OrganizerEntity>(key); oe.OrganizerId = key; oe.OrganizerName = n3.ChildNodes[0].InnerText; oe.ContinentId = continentId; oe.ContinentName = continentName; key = "4"; oe = OrganizerEntityManager.AddOrGetCacheEntity <OrganizerEntity>(key); oe.OrganizerId = key; oe.OrganizerName = n2.ChildNodes[0].InnerText; oe.ContinentId = continentId; oe.ContinentName = continentName; continue; } // 各行数据的处理 // 解析第二列所有联赛Id var a2 = n2.ChildNodes[0].Attributes["href"]; if (a2 != null) { var seasonId = RegexGetStr(a2.Value, "seasonid','", "',"); if (string.IsNullOrEmpty(seasonId)) { continue; } LeagueEntity le = LeagueEntityManager.AddOrGetCacheEntity <LeagueEntity>(seasonId); le.LeagueName = n2.InnerText; le.AddSeasonId(seasonId, true); if (!string.IsNullOrEmpty(seasonId)) { dic["4"].Add(seasonId); } } // 解析第三列所有联赛Id var a3 = n3.ChildNodes[0].Attributes["href"]; if (a3 != null) { var seasonId = RegexGetStr(a3.Value, "seasonid','", "',"); if (string.IsNullOrEmpty(seasonId)) { continue; } LeagueEntity le = LeagueEntityManager.AddOrGetCacheEntity <LeagueEntity>(seasonId); le.LeagueName = n3.InnerText; le.AddSeasonId(seasonId, true); if (!string.IsNullOrEmpty(seasonId)) { dic["393"].Add(seasonId); } } } } foreach (var kv in dic) { var oe = OrganizerEntityManager.AddOrGetCacheEntity <OrganizerEntity>(kv.Key); var cpDic = oe.CompareSetSeasonIds(kv.Value); NextAssignTask(oe, cpDic); } #endregion #region 所有其他国家的数据 var ff3 = jd3.SelectNodes("li[@class='floater ']"); // 根节点中显示的组织数据,需要进一步循环获取组织数据 if (ff3 != null) { foreach (var l3 in ff3) { var jd4 = l3.SelectSingleNode("ul[@class=' jdlvl_4']"); if (jd4 == null) { // 其他组织的联赛上一步已经处理 continue; } needNodes.AddRange(jd4.ChildNodes); } } // 需要进一步处理的Organizers数据 for (int i = 0; i < needNodes.Count; i++) { var node = needNodes[i]; var a = node.ChildNodes[0]; var organizerId = RegexGetStr(a.Attributes["href"].Value, "3_", ","); var organizerName = a.InnerText; OrganizerEntity ent = OrganizerEntityManager.AddOrGetCacheEntity <OrganizerEntity>(organizerId); ent.ContinentId = continentId; ent.ContinentName = continentName; if (node.ChildNodes.Count < 3) { // 青年 continue; } ent.OrganizerId = organizerId; ent.OrganizerName = organizerName; var lis = node.ChildNodes[2].ChildNodes; var seasonIdlist = new List <string>(); var moreLis = new List <HtmlNode>(); // 更多业余的联赛 foreach (var li in lis) { var s = li.ChildNodes[0].Attributes["href"].Value; var seasonId = RegexGetStr(s, "seasonid','", "',"); if (string.IsNullOrEmpty(seasonId)) { moreLis.Add(li); needNodes.AddRange(moreLis); continue; } LeagueEntity le = LeagueEntityManager.AddOrGetCacheEntity <LeagueEntity>(seasonId); le.LeagueName = li.InnerText; le.AddSeasonId(seasonId, true); seasonIdlist.Add(seasonId); } var cpDic = ent.CompareSetSeasonIds(seasonIdlist); NextAssignTask(ent, cpDic); } #endregion } }