Пример #1
0
        public async Task <IActionResult> CreateGame([FromBody] dynamic requestData)
        {
            Game   game     = requestData["game"].ToObject <Game>();
            string password = requestData["password"];
            await gamesRepository.SaveGameAsync(game, password);

            chatRepository.CreateGameChat(game.Id, "Public");
            storage.CreateGameStorage(game.Id, game.Players.Select(p => p.Id).ToArray());
            return(new OkObjectResult(new { game, player = game.Players.First(), gameRules = game.GameRules }));
        }
        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);
        }