protected void Page_Load(object sender, EventArgs e) { using (var currentUser = StateManager.CurrentUser) { if (IsPostBack) { string newPlayerName = Request.Form["newplayername"]; if (!string.IsNullOrWhiteSpace(newPlayerName)) { currentUser.UserName = newPlayerName; } } bool userIsAuthenticated = currentUser.IsLoggedIn; AuthenticatedUserControls.Visible = userIsAuthenticated; UnauthenticatedUser.Visible = !userIsAuthenticated; string gameid = Request.QueryString["gameid"]; CurrentGame = StateManager.Db.GetGame(gameid); if (CurrentGame != null) { GameFoundPlaceholder.Visible = true; MainForm.Attributes.Add("data-gameid", gameid); MainForm.Action = "/Game.aspx?gameid=" + gameid; GameTitle.Text = CurrentGame.GameName; GameID.Text = CurrentGame.GameId; if (!CurrentGame.Players.Any(player => player.UserId == currentUser.UserId)) { CurrentGame.Players.Add(new Player { UserId = currentUser.UserId }); } } else { GameNotKnownPlaceholder.Visible = true; } } DataBind(); }
protected void Page_Load(object sender, EventArgs e) { string newGameId = null; bool newGameIdVerified = false; int idLength = 4; while (!newGameIdVerified) { newGameId = GetRandomString(idLength); var previousGame = StateManager.Db.GetGame(newGameId); if (previousGame == null) { newGameIdVerified = true; } else { idLength++; } } var createFromListId = Request.QueryString["createfromlistid"]; var createFromListName = Request.Form["ListName"]; if (!string.IsNullOrWhiteSpace(createFromListId) || !string.IsNullOrWhiteSpace(createFromListName)) { using (var user = StateManager.CurrentUser) { Playlist playlist = null; Playlist selectedList = null; string listNameToCreate = createFromListName; if (!string.IsNullOrWhiteSpace(createFromListId)) { selectedList = SpotifyServices.GetPlaylists(user.SpotifyAuthTokens).PlayLists.FirstOrDefault(playList => playList.Id == createFromListId); if (selectedList != null && string.IsNullOrWhiteSpace(listNameToCreate)) { listNameToCreate = "DemocraticDj - " + selectedList.Name; } } playlist = SpotifyServices.CreatePlayList(user.SpotifyAuthTokens, user.SpotifyUser.Id, listNameToCreate); if (playlist != null) { var game = new Model.Game { GameId = newGameId, SpotifyPlaylistId = playlist.Id, SpotifyPlaylistUri = playlist.Uri, UserId = user.UserId, GameName = playlist.Name }; if (selectedList != null) { foreach (var track in SpotifyServices.GetTracksFromPlaylist(selectedList, user.SpotifyAuthTokens)) { game.Nominees.Add(new Nominee { TrackId = track.Id, NominatingPlayerIds = new List <string> { user.UserId } }); } } StateManager.Db.SaveGame(game); Response.Redirect("/Game.aspx?gameid=" + game.GameId); } } } DataBind(); }