public static async Task SeedAsync(FootballManagerContext catalogContext, ILoggerFactory loggerFactory, int?retry = 0) { int retryForAvailability = retry.Value; try { if (!await catalogContext.Players.AnyAsync()) { var teams = GetPreconfiguredTeams(); foreach (var team in teams) { catalogContext.Teams.Add(team); var players = GeneratePreconfiguredTeamRooster(); catalogContext.Players.AddRange(players); await catalogContext.SaveChangesAsync(); // Add the players to the team foreach (var player in players) { team.AddPlayer(player); } await catalogContext.SaveChangesAsync(); // Add players to the formation team.Formation.AddPlayer(players.First(x => x.Role == PlayerRole.Goalkeeper)); foreach (var defender in players.Where(x => x.Role == PlayerRole.Defender).Take(4)) { team.Formation.AddPlayer(defender); } foreach (var midfielder in players.Where(x => x.Role == PlayerRole.Midfielder).Take(4)) { team.Formation.AddPlayer(midfielder); } foreach (var attacker in players.Where(x => x.Role == PlayerRole.Attacker).Take(2)) { team.Formation.AddPlayer(attacker); } await catalogContext.SaveChangesAsync(); } } } catch (Exception ex) { if (retryForAvailability < 10) { retryForAvailability++; var log = loggerFactory.CreateLogger <FootballManagerContextSeed>(); log.LogError(ex.Message); await SeedAsync(catalogContext, loggerFactory, retryForAvailability); } throw; } }
public TeamRepository(FootballManagerContext dbContext) : base(dbContext) { }
public EfRepository(FootballManagerContext dbContext) { _dbContext = dbContext; }
public PlayerRepository(FootballManagerContext dbContext) : base(dbContext) { }