public override void Execute() { /* update all competition-events for next season * */ Competition.OnSeasonEnd(); //get all events for this competition var events = WorldState.GetDatabaseContext().CompetitionEvents.Where(o => o.CompetitionId == CompetitionId) .ToList(); //foreach event foreach (CompetitionEvent comp_event in events) { // tell the events to update for next season comp_event.OnSeasonEnd(); } WorldState.GetDatabaseContext().SaveChanges(); if (NextCompetitionEvent != null) { NextCompetitionEvent.Execute(); } base.Execute(); }
public override void OnMatchComplete(Match match) { Club lost_club = match.MatchLoser(); var relation = WorldState.GetDatabaseContext().CompetitionClubRelations.Where( o => o.CompetitionId == CompetitionId && o.ClubId == lost_club.Id ).First(); relation.StillInCompetition = false; WorldState.GetDatabaseContext().SaveChanges(); if (AreAllMatchesComplete()) { // matches are all done, this is the last time this function runs, so call the next event OnFinishedEvent(); //call next event, if exists if (NextCompetitionEvent != null) { NextCompetitionEvent.Execute(); } } }
public override void OnMatchComplete(Match match) { //write score of both clubs to the CompetitionLeagueTable SHOULD BE A CALLABLE FUNCTION IN CLUB? CompetitionLeagueTable homeclub_leagueitem = WorldState.GetDatabaseContext().CompetitionLeagueTable .Where(o => o.Season == match.Season && o.CompetitionEventId == Id && o.ClubId == match.HomeClubId) .First(); homeclub_leagueitem.GoalsFor += (int)match.HomeScore; homeclub_leagueitem.GoalsAgainst += (int)match.AwayScore; if (match.HomeClubWinning()) { homeclub_leagueitem.Won += 1; homeclub_leagueitem.Points += 3; } else if (match.ClubsBothTied()) { homeclub_leagueitem.Tied += 1; homeclub_leagueitem.Points += 1; } else { homeclub_leagueitem.Lost += 1; } var awayclub_leagueitem = WorldState.GetDatabaseContext().CompetitionLeagueTable .First(o => o.Season == match.Season && o.CompetitionEventId == Id && o.ClubId == match.AwayClubId); awayclub_leagueitem.GoalsFor += (int)match.AwayScore; awayclub_leagueitem.GoalsAgainst += (int)match.HomeScore; if (match.AwayClubWinning()) { awayclub_leagueitem.Won += 1; awayclub_leagueitem.Points += 3; } else if (match.ClubsBothTied()) { awayclub_leagueitem.Tied += 1; awayclub_leagueitem.Points += 1; } else { awayclub_leagueitem.Lost += 1; } WorldState.GetDatabaseContext().SaveChanges(); //if all matches complete var upcoming_match = WorldState.GetDatabaseContext().Matches .Where(o => o.CompetitionEventId == Id && o.HasEnded == false) .FirstOrDefault(); if (upcoming_match == null) { // matches are all done, this is the last time this function runs, so call the next event OnFinishedEvent(); //call next event, if exists if (NextCompetitionEvent != null) { NextCompetitionEvent.Execute(); } } }