public async Task <Guid?> CreateJoinGame(JoinCreateGame game) { switch (game.Command) { case "CREATE": { var config = new MapperConfiguration(cfg => cfg.CreateMap <BLL.Games.Common.Card, Domain.Card>()); var mapper = config.CreateMapper(); var bussijuht = new Bussijuht(); bussijuht.InitializeGame(game.Players); var board = bussijuht.Board.Select(e => mapper.Map <BLL.Games.Common.Card, Domain.Card>(e)).ToList(); // Create a player who joined the game var activeGame = new ActiveGame { Id = Guid.NewGuid(), Name = game.Game, MaxPlayers = game.Players, Code = GenerateRandomGameCode(), IsActive = true, Board = board, Players = new List <Player>() // Add player to player list }; await _repository.Add(activeGame); return(activeGame.Id); } case "JOIN": // var existingGame = _repository.FindGameByCode(game.Code); // Find the game with id // If game exists, return the id of the game // If game does not exist, return error message break; default: // Something went wrong break; } return(null); }
public async Task <ActionResult <ActiveGame> > PostActiveGame(JoinCreateGame game) { var gameId = await _service.CreateJoinGame(game); return(CreatedAtAction("GetActiveGame", gameId)); }