public static IApplicationBuilder MigrateDatabase(this IApplicationBuilder app)
        {
            GoTGameContextDb context = app.ApplicationServices.GetRequiredService <GoTGameContextDb>();

            context.Database.Migrate();
            IdentityContextDb identityContext = app.ApplicationServices.GetRequiredService <IdentityContextDb>();

            identityContext.Database.Migrate();

            return(app);
        }
        public static IApplicationBuilder UseGoTStorage(this IApplicationBuilder app)
        {
            IGoTStorage      storage = app.ApplicationServices.GetRequiredService <IGoTStorage>();
            GoTGameContextDb context = app.ApplicationServices.GetRequiredService <GoTGameContextDb>();

            var games = context.Games.ToList();

            foreach (Game game in games)
            {
                var playerIds = context.Players.Where(p => p.GameId == game.Id).Select(p => p.Id).ToArray();
                storage.CreateGameStorage(game.Id, playerIds);
            }

            return(app);
        }
Beispiel #3
0
        public static void PopulateGame(IApplicationBuilder app)
        {
            GoTGameContextDb context  = app.ApplicationServices.GetRequiredService <GoTGameContextDb>();
            IChatRepository  chatRepo = app.ApplicationServices.GetRequiredService <IChatRepository>();

            bool saveNeeded = false;

            if (!context.Games.Any())
            {
                context.Games.AddRange(new[]
                {
                    new Game {
                        Name      = "Temporary game",
                        GameRules = new GameRules {
                            AllHouses       = false,
                            RandomHouses    = false,
                            MaxPlayers      = 6,
                            WinCondition    = WinCondition.Castles,
                            WinCastlesCount = 7,
                            RoundsCount     = 10
                        }
                    }
                });

                saveNeeded = true;
            }

            if (saveNeeded)
            {
                context.SaveChanges();
            }

            foreach (var game in context.Games)
            {
                chatRepo.CreateGameChat(game.Id, "Public");
            }
        }
Beispiel #4
0
 public ChatRepository(GoTGameContextDb context, IGoTStorage storage, IPlayersRepository playersRepository)
     : base(context, storage)
 {
     gameChats = new List <GameChat>();
     this.playersRepository = playersRepository;
 }
Beispiel #5
0
 public PlayersRepository(GoTGameContextDb context, IGoTStorage storage, IGamesRepository gamesRepo)
     : base(context, storage)
 {
     gamesRepository = gamesRepo;
 }
Beispiel #6
0
 public BaseRepository(GoTGameContextDb context, IGoTStorage storage)
 {
     this.context = context;
     this.storage = storage;
 }
Beispiel #7
0
 public GameRulesRepository(GoTGameContextDb context)
 {
     this.context = context;
 }
Beispiel #8
0
 public GamesRepository(GoTGameContextDb context, IPasswordHasher <Game> passwordHasher)
 {
     this.context        = context;
     this.passwordHasher = passwordHasher;
 }