static public SoccerWorldDatabaseContext GetDatabaseContext() { if (_context == null) { _context = SoccerWorldDatabaseContext.GetService(); } return(_context); //return SoccerWorldDatabaseContext.GetService(); }
static public IEnumerable <CompetitionLeagueTable> GetStandings(CompetitionEvent comp_event, int season) { var list = SoccerWorldDatabaseContext.GetService().CompetitionLeagueTable .Where(o => o.Season == season && o.CompetitionEventId == comp_event.Id) .Include(o => o.Club) .ToList(); list.Sort(new StandingOrderComparer(backwards: false)); return(list); }
static public IEnumerable <CompetitionLeagueTable> GetStandingsBackwards(Competition comp, int season) { var first_tableitem = SoccerWorldDatabaseContext.GetService().CompetitionLeagueTable .Where(o => o.Season == season && o.CompetitionId == comp.Id) .Include(o => o.CompetitionEvent) .First(); CompetitionEvent first_event = first_tableitem.CompetitionEvent; return (GetStandingsBackwards(first_event, season)); }
////////////////////////////// public async void CompetitionsDataRequest(int?id) { if (id == null) { await Clients.Caller.SendAsync("OnCompetitionsDataRequest", "{}"); return; } using (var context = SoccerWorldDatabaseContext.GetService()) { var comps = context.Competitions .Where(c => c.CountryId == id) .ToList(); await Clients.Caller.SendAsync("OnCompetitionsDataRequest", JsonConvert.SerializeObject(SerializeCompetitions(comps))); } }
public async void CompetitionDataRequest(int id, int?season, int?round) { using (var context = SoccerWorldDatabaseContext.GetService()) { var comp = context.Competitions .Where(c => c.Id == id) .Include(c => c.Country).First(); if (comp.Country.Season == null) { await Clients.Caller.SendAsync("OnCompetitionDataRequest", JsonConvert.SerializeObject( new { Competition = new CompetitionViewModel(comp), CompetitionSeasons = new Array[0], LeagueTable = new Array[0], Matches = new Array[0] } )); return;//nullable-int syndrome solution #1 } if (season == null) { season = comp.Country.Season; } var country_seasons = context.CompetitionLeagueTable.Where(o => o.Competition == comp) .Select(o => o.Season) .Distinct().ToList(); //TODO.OrderBy(); // var standings = CompetitionLeagueTable.GetStandings(comp, (int)season); if (round == null) { var chosen_match = context.Matches .Where(m => m.Season == season && m.CompetitionEvent.CompetitionId == comp.Id && m.HasEnded == false) .OrderBy(m => m.RoundNumber).FirstOrDefault(); if (chosen_match == null) { chosen_match = context.Matches .Where(m => m.Season == season && m.CompetitionEvent.CompetitionId == comp.Id && m.HasEnded == true) .OrderByDescending(m => m.RoundNumber).FirstOrDefault(); } round = chosen_match?.RoundNumber; } var matches = context.Matches .Where(m => m.Season == season && m.CompetitionEvent.CompetitionId == comp.Id && m.RoundNumber == round) .Include(m => m.HomeClub) .Include(m => m.AwayClub) .ToList(); await Clients.Caller.SendAsync("OnCompetitionDataRequest", JsonConvert.SerializeObject( new { Competition = new CompetitionViewModel(comp), CompetitionSeasons = country_seasons, LeagueTable = SerializeStandings(standings), Matches = SerializeMatches(matches) } )); } }
static public IEnumerable <CompetitionLeagueTable> GetStandings(int competition_id) { var comp = SoccerWorldDatabaseContext.GetService().Competitions.Where(c => c.Id == competition_id).First(); return(GetStandings(comp, (int)comp.Country.Season)); }