public UnitOfWork(
     FootballContext context,
     IRepository <Match> matchRepository,
     IRepository <Manager> managerRepository,
     IRepository <Referee> refereeRepository,
     IRepository <Player> playerRepository,
     IRepository <PlayerMatch> playerMatchRepository)
 {
     MatchRepository       = matchRepository;
     this.context          = context;
     ManagerRepository     = managerRepository;
     RefereeRepository     = refereeRepository;
     PlayerRepository      = playerRepository;
     PlayerMatchRepository = playerMatchRepository;
 }
Esempio n. 2
0
 public BaseRepository(FootballContext context)
 {
     this.context = context;
     dbSet        = context.Set <TEntity>();
 }
Esempio n. 3
0
        public static void Initialize(FootballContext context)
        {
            context.Database.EnsureCreated();

            if (context.Players.Any())
            {
                return;
            }

            var players = new Player[]
            {
                new Player {
                    Name = "Lionel"
                },
                new Player {
                    Name = "Cristiano"
                },
                new Player {
                    Name = "Iker"
                },
                new Player {
                    Name = "Gerard"
                },
                new Player {
                    Name = "Philippe"
                },
                new Player {
                    Name = "Jordi"
                },
                new Player {
                    Name = "Alejandro", YellowCard = 2
                }
            };

            foreach (var p in players)
            {
                context.Players.Add(p);
            }
            context.SaveChanges();

            var managers = new Manager[]
            {
                new Manager {
                    Name = "Alex"
                },
                new Manager {
                    Name = "Zidane"
                },
                new Manager {
                    Name = "Guardiola"
                }
            };

            foreach (var m in managers)
            {
                context.Managers.Add(m);
            }
            context.SaveChanges();

            var referees = new Referee[]
            {
                new Referee {
                    Name = "Pierluigi"
                },
                new Referee {
                    Name = "Howard"
                }
            };

            foreach (var r in referees)
            {
                context.Referees.Add(r);
            }
            context.SaveChanges();
        }