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 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"); } }