public async Task <IActionResult> DeleteChannels([FromBody] ICollection <Guid> ids)
        {
            if (ids == null)
            {
                return(BadRequest());
            }

            foreach (var id in ids)
            {
                var entry = await _playlistContext.PlaylistEntries.FindAsync(id);

                if (entry == null)
                {
                    _logger.LogDebug($"Could not delete! Channel {id} not found");
                    continue;
                }

                _logger.LogInformation($"Deleting channel {id} - {entry.Name}");
                _playlistContext.PlaylistEntries.Remove(entry);
            }

            await _playlistContext.SaveChangesAsync();

            return(Ok());
        }
Exemplo n.º 2
0
        public async Task <ActionResult <Room> > CreateRoom(string userToken, [FromBody] Room room)
        {
            if (string.IsNullOrEmpty(userToken))
            {
                throw new ArgumentException();
            }

            var decodedToken = JWT.Decode(userToken);
            var token        = JsonConvert.DeserializeAnonymousType(decodedToken, new { Name = "" });

            try
            {
                if (room?.RoomSongs?.Any(s => s.Song != null) ?? false)
                {
                    foreach (var roomSong in room.RoomSongs)
                    {
                        var song = await _context.Songs.FirstOrDefaultAsync(s => $"{s.Name} {s.Artist}" == $"{roomSong.Song.Name} {roomSong.Song.Artist}");

                        if (song != null)
                        {
                            roomSong.SongId = song.Id;
                        }
                    }
                }

                room.Owner = token.Name;
                _context.Rooms.Add(room);
                await _context.SaveChangesAsync();
            }
            catch
            {
                throw new SystemWeb.HttpResponseException(HttpStatusCode.InternalServerError);
            }
            return(CreatedAtAction(nameof(GetSingleRoom), new { room.Id }, room));
        }
Exemplo n.º 3
0
        public async Task <ActionResult <Playlist> > PutPlaylist(int id, Playlist playlist)
        //public async Task<IActionResult> PutPlaylist(int id, Playlist playlist)
        {
            if (id != playlist.Id)
            {
                return(BadRequest());
            }

            _context.Entry(playlist).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PlaylistExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            var res = await _context.Playlists.FindAsync(id);

            return(res);

            //return NotFound();
        }
        public async Task <IActionResult> PutPlaylistItem(long id, PlaylistItem playlistItem)
        {
            if (id != playlistItem.id)
            {
                return(BadRequest());
            }

            _context.Entry(playlistItem).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PlaylistItemExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 5
0
        public async Task <IActionResult> PutTrack(int id, Track track)
        {
            if (id != track.Id)
            {
                return(BadRequest());
            }

            _context.Entry(track).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TrackExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 6
0
        public async Task <string> SaveTokenAsync(string token)
        {
            var jwtToken = new Token()
            {
                JWTToken = token
            };

            await _playlistContext.Tokens.AddAsync(jwtToken);

            await _playlistContext.SaveChangesAsync();

            return(jwtToken.JWTToken);
        }
        public async Task <IActionResult> OnPostAsync()
        {
            PlaylistModel.ProprietaireName = User.Identity.Name;

            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(PlaylistModel).State = EntityState.Modified;

            try {
                await _context.SaveChangesAsync();
            } catch (DbUpdateConcurrencyException) {
                if (!PlaylistModelExists(PlaylistModel.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
Exemplo n.º 8
0
        public async Task <IActionResult> Edit(Guid id, PlaylistEntry updatedEntry)
        {
            if (updatedEntry == null)
            {
                return(NotFound());
            }

            if (id != updatedEntry.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                var entry = await _playlistContext.PlaylistEntries.FindAsync(id);

                if (entry == null)
                {
                    return(NotFound());
                }

                entry.Position            = updatedEntry.Position;
                entry.ChannelNumberExport = updatedEntry.ChannelNumberExport;
                entry.EpgMatchName        = updatedEntry.EpgMatchName;
                entry.IsEnabled           = updatedEntry.IsEnabled;
                entry.LogoUrl             = updatedEntry.LogoUrl;
                entry.Modified            = DateTime.Now;

                await _playlistContext.SaveChangesAsync();

                return(RedirectToAction("Index", "Home"));
            }

            return(View(updatedEntry));
        }
        public async Task <bool> DeleteItemAsync(string id)
        {
            var roomSong = GetItemAsync(id);

            _playlistContext.RoomSongs.Remove(await roomSong);
            await _playlistContext.SaveChangesAsync();

            return(true);
        }
Exemplo n.º 10
0
        public async Task <Room> AddSongToRoomAsync(string userToken, string roomId, Song song)
        {
            try
            {
                var roomIdAsInt = Convert.ToInt32(roomId);
                var room        = await GetItemAsync(roomId);

                var playlist     = _playlistsContext.SpotifyPlaylist.SingleOrDefaultAsync(s => s.RoomId == roomIdAsInt);
                var matchingSong = _playlistsContext.Songs.FirstOrDefaultAsync(s => $"{s.Artist}{s.Name}" == $"{song.Artist}{song.Name}");
                var decodedToken = JWT.Decode(userToken);
                var token        = JsonConvert.DeserializeAnonymousType(decodedToken, new { Name = "" });

                if (room == null)
                {
                    throw new Exception("Could not find room");
                }

                var roomSong = new RoomSong()
                {
                    RoomId      = roomIdAsInt,
                    SongId      = (await matchingSong)?.Id ?? 0,
                    Song        = song,
                    SongAddedBy = token.Name,
                };

                if (await playlist != null)
                {
                    var playlistTable = await playlist;
                    var service       = new SpotifyService(playlistTable.AuthCode);

                    if (string.IsNullOrEmpty(song.SpotifyId))
                    {
                        var spotifySong = await service.GetSong(song.Name);

                        await service.AddSongToPlaylist(playlistTable, spotifySong);

                        song.SpotifyId = spotifySong.SpotifyId;
                    }
                    else
                    {
                        await service.AddSongToPlaylist(playlistTable, song);
                    }
                }
                if (!room.RoomSongs.Any(s => s.SongId == roomSong.SongId))
                {
                    room.RoomSongs.Add(roomSong);
                    await _playlistsContext.SaveChangesAsync();
                }

                return(room);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
 public async Task<SpotifyPlaylist> AddItemAsync(SpotifyPlaylist item)
 {
     try
     {
         await _playlistContext.SpotifyPlaylist.AddAsync(item);
         await _playlistContext.SaveChangesAsync();
         return item;
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemplo n.º 12
0
        public async Task <IActionResult> OnPostAsync(string id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            PlaylistModel = await _context.Playlists.FindAsync(id);

            if (PlaylistModel != null)
            {
                _context.Playlists.Remove(PlaylistModel);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Exemplo n.º 13
0
        public async Task <IActionResult> OnPostAsync()
        {
            Console.WriteLine("onPost");
            PlaylistModel.ProprietaireName = User.Identity.Name;
            PlaylistModel.Musiques         = new List <Musique>();
            PlaylistModel.Tags             = new List <Tags>();

            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Playlists.Add(PlaylistModel);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
        public async Task SynchronizeAsync()
        {
            _logger.LogDebug(LoggingEvents.Synchronize, "Synchronizing playlist from server...");

            var tv7Url          = GetTv7SourceUrl();
            var existingEntries = await _playlistContext.PlaylistEntries.ToDictionaryAsync(e => e.ChannelNumberImport);

            var tracks = await _playlistLoader.LoadPlaylistFromUrl(tv7Url);

            MarkNotAvailableEntries(existingEntries, tracks);
            AddOrUpdateEntries(existingEntries, tracks);

            _logger.LogDebug("Synchronizing playlist completed saving changes...");

            await _playlistContext.SaveChangesAsync();

            _logger.LogDebug("Playlist changes saved successfully...");
        }
Exemplo n.º 15
0
        public async Task <Room> AddItemAsync(Room room, string userToken)
        {
            // TODO: Should probably verify the userToken, but it's not necessary at this point
            // When we reimplement the API we'll definitely have to do it
            if (string.IsNullOrEmpty(userToken))
            {
                throw new ArgumentException();
            }

            try
            {
                // If we're given a room with songs, we need to make sure
                // to populate the room table with the correct song data
                if (room?.RoomSongs?.Any(s => s.Song != null) ?? false)
                {
                    foreach (var roomSong in room.RoomSongs)
                    {
                        var song = await _playlistsContext.Songs.FirstOrDefaultAsync(s => $"{s.Name} {s.Artist}" == $"{roomSong.Song.Name} {roomSong.Song.Artist}");

                        if (song != null)
                        {
                            roomSong.SongId = song.Id;
                        }
                    }
                }

                _playlistsContext.Rooms.Add(room);
                await _playlistsContext.SaveChangesAsync();

                return(room);
            }
            catch
            {
                throw;
            }
        }
Exemplo n.º 16
0
        public async Task <ActionResult <string> > CreateToken()
        {
            var payload = new Dictionary <string, object>()
            {
                { "id", Guid.NewGuid() },
                { "name", GenerateName() },
            };

            string tokenString = JWT.Encode(payload, null, JwsAlgorithm.none);
            var    token       = new Token()
            {
                JWTToken = tokenString
            };
            await _context.Tokens.AddAsync(token);

            await _context.SaveChangesAsync();

            return(tokenString);
        }