public async Task <IActionResult> AddSongToRoom(RoomVM roomVM)
        {
            var spotify = new SpotifyService(roomVM.CurrentRoom.SpotifyAuthCode);
            var song    = await spotify.GetSong(roomVM.SongToAdd);

            var  token    = Request.Headers["Authorization"].ToString().Replace("Bearer ", "");
            var  username = _tokenService.GetNameFromToken(token);
            Room room     = null;

            try
            {
                room = await _roomDataStore.AddSongToRoomAsync(username, roomVM.CurrentRoom.Id.ToString(), song);

                var playlist = await _spotifyPlaylistsStore.GetItemByRoomId(room.Id.ToString());

                await spotify.AddSongToPlaylist(playlist, song);

                await _roomDataStore.RemovePreviouslyPlayedSongsAsync(room.Id);
            }
            catch { }


            if (room != null)
            {
                await _roomHub.Clients.All.SendAsync("Update", room.Id.ToString());

                return(PartialView("Components/_roomSongListItem", room.RoomSongs));
            }

            return(PartialView("Components/_roomSongListItem", room.RoomSongs));
        }
        public async Task <Room> AddSongToRoom(int roomId, [FromBody] Song songToAdd)
        {
            var roomDataStore      = new RoomDataStore(_playlistContext);
            var token              = Request.Headers["Authorization"].ToString().Replace("Bearer ", "");
            var usernameAddingSong = new TokenService(_playlistContext, _config).GetNameFromToken(token);

            return(await roomDataStore.AddSongToRoomAsync(usernameAddingSong, roomId.ToString(), songToAdd));
        }
示例#3
0
        public async Task AddSongToRoomAsync_GivenRoomIDAndSong_ReturnRoomWithSong()
        {
            var roomdatastore = new RoomDataStore(_playlistContext);

            Assert.AreEqual(0, (await roomdatastore.GetItemAsync("2")).RoomSongs.Count);

            var room = await roomdatastore.AddSongToRoomAsync(_token, "2", _songs[0]);

            Assert.IsNotNull(room);
            Assert.AreEqual(1, room.RoomSongs.Count);
            Assert.AreEqual(1, (await roomdatastore.GetItemAsync("2")).RoomSongs.Count);
        }
        public async Task AddSongToRoomAsync_GivenRoomIDAndSong_ReturnRoomWithSong()
        {
            var roomdatastore = new RoomDataStore(_playlistContext);

            var song = new Song()
            {
                Name = "Test Song", Id = 0, Artist = "Swaylo", SpotifyId = "1"
            };

            Assert.AreEqual(0, (await roomdatastore.GetItemAsync("1")).RoomSongs.Count);

            var room = await roomdatastore.AddSongToRoomAsync(_token, "1", song);

            Assert.IsNotNull(room);
            Assert.AreEqual(1, room.RoomSongs.Count);
            Assert.AreEqual(1, (await roomdatastore.GetItemAsync("1")).RoomSongs.Count);
        }