public IActionResult Create(EditLobbyViewModel lobby) { try { _service.CreateLobby(currentUserId, lobby.Name, lobby.Private); } catch (ArgumentOutOfRangeException ex1) { return(NotFound(ex1)); } return(RedirectToAction("Index")); }
public IActionResult CreateLobby([FromBody] LobbyCreationDto newLobby) { try { if (ModelState.IsValid) { try { var userId = _authorizationService.GetUserId(User); var lobbyResult = _lobbyService.CreateLobby(newLobby, userId); if (lobbyResult != null) { return(CreatedAtRoute("GetLobby", new { id = lobbyResult.Id }, lobbyResult)); } } catch { } return(Unauthorized()); } return(BadRequest()); } catch { return(Unauthorized()); } }
public Lobby Post([FromBody] Lobby lobby) { if (lobby != null) { return(lobbyService.CreateLobby(lobby)); } else { return(null); } }
public async Task CreateLobby(Lobby lobby) { if (lobby != null) { lobbyService.CreateLobby(lobby); } Groups.AddToGroupAsync(Context.ConnectionId, lobby.Id.ToString()); await Clients.Groups(lobby.Id.ToString()).LobbyCreated(lobby); await Clients.Group(lobby.Id.ToString()).AddedToGroup(lobby.Id.ToString()); }
public void AddLobby(string name, string pass) { GameLobby newLobby; PlayerModel creator; List <GameLobby> lobbies; creator = userService.GetByConnectionId(Context.ConnectionId); newLobby = new GameLobby { LobbyName = name, Password = pass, Creator = creator.CurrentConnectionId }; newLobby.CreatorElo = creator.Elo; lobbyService.CreateLobby(newLobby); lobbies = lobbyService.GetAllLobbies().OrderByDescending(x => x.CreatorElo).ToList(); Clients.All.getLobbies(lobbies); }
public async Task CreateLobby(string lobbyName) { var joinedLobby = _lobbyService.GetJoinedLobby(Context.ConnectionId); if (joinedLobby != null) { throw new HubException("You can't create a lobby while you're in a lobby"); } if (_lobbyService.GetLobby(lobbyName) != null) { throw new HubException($"Lobby with the name '{lobbyName}' already exists"); } _lobbyService.CreateLobby(lobbyName, Context.ConnectionId); await JoinLobby(lobbyName); }