static void Main(string[] args) { using (var context = new TtcDbContext()) { try { // This code can be triggered from the UI! // Admin > Spelers > Frenoy Sync button (float: right) //var vttlPlayers = new FrenoyPlayersApi(context, Competition.Vttl); //vttlPlayers.StopAllPlayers(true); //vttlPlayers.SyncPlayers(); //var sportaPlayers = new FrenoyPlayersApi(context, Competition.Sporta); //sportaPlayers.SyncPlayers(); // This code can be triggered by deploying a new migration // --> No more at the moment with asyncy stuff see README. var vttl = new FrenoyMatchesApi(context, Competition.Vttl); vttl.SyncTeamsAndMatches(); var sporta = new FrenoyMatchesApi(context, Competition.Sporta); sporta.SyncTeamsAndMatches(); //RandomizeMatchDatesForTestingPurposes(context); context.SaveChanges(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); Console.ReadKey(); } } }
public async Task FrenoyTeamSync(int teamId) { using (var db = new TtcDbContext()) { var team = await db.Teams.SingleAsync(x => x.Id == teamId); var frenoySync = new FrenoyMatchesApi(db, Constants.NormalizeCompetition(team.Competition)); await frenoySync.SyncTeamMatches(team); } }
private static async Task FrenoyMatchSyncCore(TtcDbContext dbContext, int matchId, bool forceSync) { var match = await dbContext.Matches .WithIncludes() .Include(x => x.HomeTeam) .Include(x => x.AwayTeam) .SingleAsync(x => x.Id == matchId); if (forceSync || (match.Date < DateTime.Now && !match.IsSyncedWithFrenoy)) { var frenoySync = new FrenoyMatchesApi(dbContext, match.Competition, forceSync); await frenoySync.SyncMatchDetails(match); } }
/// <summary> /// Adds the matches and syncs the players for the new season /// </summary> /// <returns>The new season year</returns> public static async Task <int> Seed(TtcDbContext context, bool clearMatches) { // TODO: Season 2020: Add GetOpponentMatches to initial seed (remove from MatchService) //if (clearMatches) //{ // context.Database.ExecuteSqlCommand("DELETE FROM matchplayer"); // context.Database.ExecuteSqlCommand("DELETE FROM matchgame"); // context.Database.ExecuteSqlCommand("DELETE FROM matchcomment"); // context.Database.ExecuteSqlCommand("DELETE FROM matches"); //} //int newYear = context.CurrentFrenoySeason + 1; int newYear = DateTime.Today.Year; int newFrenoyYear = newYear - 2000 + 1; if (DateTime.Today.Month < 7) { throw new Exception($"Starting new season {newYear}? That doesn't seem right?"); } if (!context.Matches.Any(x => x.FrenoySeason == newFrenoyYear)) { // VTTL var vttlPlayers = new FrenoyPlayersApi(context, Competition.Vttl); await vttlPlayers.StopAllPlayers(true); await vttlPlayers.SyncPlayers(); var vttl = new FrenoyMatchesApi(context, Competition.Vttl); await vttl.SyncTeamsAndMatches(); // Sporta var sportaPlayers = new FrenoyPlayersApi(context, Competition.Sporta); await sportaPlayers.StopAllPlayers(true); await sportaPlayers.SyncPlayers(); var sporta = new FrenoyMatchesApi(context, Competition.Sporta); await sporta.SyncTeamsAndMatches(); } //CreateSystemUser(context); return(newYear); }
public async Task <ICollection <OtherMatch> > GetOpponentMatches(int teamId, OpposingTeam opponent = null) { using (var dbContext = new TtcDbContext()) { var team = await dbContext.Teams.SingleAsync(x => x.Id == teamId); async Task <MatchEntity[]> GetMatchEntities() { // ReSharper disable AccessToDisposedClosure var matches = dbContext.Matches .WithIncludes() .Where(match => match.FrenoyDivisionId == team.FrenoyDivisionId); // ReSharper restore AccessToDisposedClosure if (opponent != null) { matches = matches.Where(match => (match.AwayClubId == opponent.ClubId && match.AwayTeamCode == opponent.TeamCode) || (match.HomeClubId == opponent.ClubId && match.HomeTeamCode == opponent.TeamCode) ); } return(await matches.ToArrayAsync()); } MatchEntity[] matchEntities = await GetMatchEntities(); if (opponent != null) { // TODO BUG: This means that when called from Team Week Overview, no opponent is set and there is no sync... // TODO PERFORMANCE: This executes too many times, make it part of initial competition load var frenoy = new FrenoyMatchesApi(dbContext, Constants.NormalizeCompetition(team.Competition)); await frenoy.SyncOpponentMatches(team, opponent); matchEntities = await GetMatchEntities(); } // No comments for OpponentMatches var result = Mapper.Map <IList <MatchEntity>, IList <OtherMatch> >(matchEntities); return(result); // TODO: Bug PreSeason code: This doesn't work! These results are NOT displayed in the MatchCard, the spinner just keeps on spinnin' // Pre season: Fetch last year matches instead //int? divisionId = frenoy.SyncLastYearOpponentMatches(team, opponent); //if (divisionId.HasValue) //{ // var matchEntities = dbContext.Matches // .WithIncludes() // .Where(match => (match.AwayClubId == opponent.ClubId && match.AwayTeamCode == opponent.TeamCode) || (match.HomeClubId == opponent.ClubId && match.HomeTeamCode == opponent.TeamCode)) // .Where(match => match.FrenoyDivisionId == divisionId.Value) // .ToList(); // // No comments for OpponentMatches // // HACK: hack om vorig jaar matchen te tonen in de frontend zonder te moeten berekenen wat hun "last year division id" is // foreach (var match in matchEntities) // { // match.FrenoyDivisionId = team.FrenoyDivisionId; // } // var result = Mapper.Map<IList<MatchEntity>, IList<OtherMatch>>(matchEntities); // return result; //} } }