public List <GameLetters> CreateGameRoom() { GameRoom gr = new GameRoom(); dbContext.GameRoom.Add(gr); dbContext.SaveChanges(); Random random = new Random(); for (int i = 0; i < 16; i++) { GameLetters gl = new GameLetters(); gl.GameRoomId = gr.Id; gl.Position = i; gl.Letter = dice[i][random.Next(0, 6)]; //TODO Random letter from table dbContext.GameLetters.Add(gl); dbContext.SaveChanges(); } GameParticipants gp = new GameParticipants(); gp.GameRoomId = gr.Id; gp.UserId = dbContext.GetCurrentUserId(); dbContext.GameParticipants.Add(gp); dbContext.SaveChanges(); return(dbContext.GameLetters.Where(x => x.GameRoomId == gr.Id).ToList()); }
public bool JoinGameRoom(long roomId) { GameRoom gr = dbContext.GameRoom.Find(roomId); if (gr.StartTime != null) { return(false); } GameParticipants gp = new GameParticipants(); gp.GameRoomId = roomId; gp.UserId = dbContext.GetCurrentUserId(); dbContext.GameParticipants.Add(gp); dbContext.SaveChanges(); return(true); }