public async Task <AlbumSong> AddAlbumSong(AlbumSong albumSong)
        {
            await _context.AlbumSongs.AddAsync(albumSong);

            await _context.SaveChangesAsync();

            return(albumSong);
        }
예제 #2
0
        public void Add(int albumId, int artistId, int trackNumber, int songId)
        {
            var album  = _context.Album.FirstOrDefault(g => g.Id == albumId);
            var artist = _context.Artist.FirstOrDefault(a => a.Id == artistId);
            var song   = _context.Song.FirstOrDefault(a => a.Id == songId);

            var newAlbumSong = new AlbumSong
            {
                Artist      = artist,
                Album       = album,
                TrackNumber = trackNumber,
                Song        = song
            };

            _context.Add(newAlbumSong);
            _context.SaveChanges();
        }
예제 #3
0
        public bool Edit(EditAlbumDto editInfo)
        {
            try
            {
                var album = this.context.Albums.Find(editInfo.Id);
                if (album == null)
                {
                    return(false);
                }

                album.Name           = editInfo.Name;
                album.Genre          = editInfo.Genre;
                album.ReleaseDate    = editInfo.ReleaseDate;
                album.ReleaseStage   = editInfo.ReleaseStage;
                album.SpotifyLink    = editInfo.SpotifyLink;
                album.AlbumCoverLink = editInfo.AlbumCoverLink;
                album.ApprovalStatus = ApprovalStatus.Pending;
                album.AlbumsSongs.Clear();

                if (editInfo.SelectedSongIds != null)
                {
                    foreach (var songId in editInfo.SelectedSongIds)
                    {
                        var currentAlbumSong = this.context.AlbumsSongs.FirstOrDefault(s => s.SongId == songId && s.AlbumId == editInfo.Id);
                        if (currentAlbumSong == null)
                        {
                            currentAlbumSong = new AlbumSong
                            {
                                SongId = songId,
                            };
                        }

                        album.AlbumsSongs.Add(currentAlbumSong);
                    }
                }

                this.context.Albums.Update(album);
                this.context.SaveChanges();
                return(true);
            }
            catch
            {
                return(false);
            }
        }
예제 #4
0
        private async Task <Album> GetAlbumQuery()
        {
            var response = await _lastfmClient.Album.GetInfoAsync(SwitchArtist(ArtistName), AlbumName);

            if (response.Success)
            {
                var lastfmAlbum = response.Content;

                var album = new Album
                {
                    Site           = "LastFM",
                    Artist         = lastfmAlbum.ArtistName,
                    Title          = lastfmAlbum.Name,
                    SmallImageUrl  = lastfmAlbum.Images.Small.AbsoluteUri,
                    MediumImageUrl = lastfmAlbum.Images.Medium.AbsoluteUri,
                    LargeImageUrl  = lastfmAlbum.Images.Large.AbsoluteUri
                };

                var discs       = new List <List <AlbumSong> >();
                var albumTracks = new List <AlbumSong>();
                var i           = 0;
                foreach (var track in lastfmAlbum.Tracks)
                {
                    i++;
                    var albumtrack = new AlbumSong();
                    albumtrack.Title    = track.Name;
                    albumtrack.Duration = track.Duration.ToString();
                    albumtrack.Number   = i;
                    albumTracks.Add(albumtrack);
                }

                discs.Add(albumTracks);
                album.Discs = discs;
                Albums.Add(album);
            }

            // We don't need to return really anything. Just to satisfy that a Task can't return void
            return(null);
        }
예제 #5
0
        public bool Create(CreateAlbumDto creationInfo)
        {
            try
            {
                var album = new Album
                {
                    Name           = creationInfo.Name,
                    Genre          = creationInfo.Genre,
                    ReleaseDate    = creationInfo.ReleaseDate,
                    ReleaseStage   = creationInfo.ReleaseStage,
                    SpotifyLink    = creationInfo.SpotifyLink,
                    AlbumCoverLink = creationInfo.AlbumCoverLink,
                    ArtistId       = creationInfo.ArtistId,
                    ApprovalStatus = ApprovalStatus.Pending
                };

                if (creationInfo.SelectedSongIds != null)
                {
                    foreach (var songId in creationInfo.SelectedSongIds)
                    {
                        var currentAlbumSong = new AlbumSong
                        {
                            SongId = songId,
                        };

                        album.AlbumsSongs.Add(currentAlbumSong);
                    }
                }

                this.context.Albums.Add(album);
                this.context.SaveChanges();
                return(true);
            }
            catch
            {
                return(false);
            }
        }
예제 #6
0
        private static void AddSongToAlbum()
        {
            bool isCorrect = false;

            do
            {
                Clear();

                Write("Album (titel): ");

                string albumTitle = ReadLine();

                Write("Låt (titel): ");

                string songName = ReadLine();

                WriteLine();

                WriteLine("Är detta korrekt? (J)a eller (N)ej");


                ConsoleKeyInfo keyPressed;

                bool isValidKey = false;

                do
                {
                    keyPressed = ReadKey(true);

                    isValidKey = keyPressed.Key == ConsoleKey.J ||
                                 keyPressed.Key == ConsoleKey.N;
                } while (!isValidKey);

                if (keyPressed.Key == ConsoleKey.J)
                {
                    isCorrect = true;

                    if (context.Album.Any(x => x.AlbumTitle == albumTitle) &&
                        context.Song.Any(x => x.SongName == songName))
                    {
                        Album album = context.Album.FirstOrDefault(x => x.AlbumTitle == albumTitle);
                        Song  song  = context.Song.FirstOrDefault(x => x.SongName == songName);

                        AlbumSong albumSong = new AlbumSong(song.Id);

                        album.AlbumSongs.Add(albumSong);
                        context.SaveChanges();

                        WriteLine("Låt tillagd till album");
                        Thread.Sleep(2000);
                    }
                    else
                    {
                        WriteLine("Låt eller elev saknas");
                        Thread.Sleep(2000);
                    }
                }

                Clear();
            } while (!isCorrect);
        }
예제 #7
0
        private async Task <Album> GetRelease(int releaseid)
        {
            log.Trace($"Discogs: Receiving Release {releaseid}");
            var release = await _discogsClient.GetMasterAsync(releaseid);

            var album = new Album();

            album.Site = "Discogs";
            var discogsImage = release.images.FirstOrDefault(i => i.type == DiscogsImageType.primary);;

            if (discogsImage != null)
            {
                album.LargeImageUrl = discogsImage.uri;
                album.CoverHeight   = discogsImage.height.ToString();
                album.CoverWidth    = discogsImage.width.ToString();
            }

            album.Artist    = string.Join(",", release.artists.Select(a => a.name));
            album.Title     = release.title;
            album.Year      = release.year.ToString();
            album.DiscCount = 1;

            // Get the Tracks
            var discs               = new List <List <AlbumSong> >();
            var albumTracks         = new List <AlbumSong>();
            var numDiscs            = 1;
            var lastPosOnAlbumSideA = 0;

            foreach (var track in release.tracklist)
            {
                var pos        = track.position;
                var albumTrack = new AlbumSong();

                if (string.IsNullOrEmpty(track.position) || string.IsNullOrEmpty(track.title))
                {
                    continue;
                }

                // check for Multi Disc Album
                if (track.position.Contains("-"))
                {
                    album.DiscCount = Convert.ToInt16(track.position.Substring(0, track.position.IndexOf("-", StringComparison.Ordinal)));
                    // Has the number of Discs changed?
                    if (album.DiscCount != numDiscs)
                    {
                        numDiscs = album.DiscCount;
                        discs.Add(new List <AlbumSong>(albumTracks));
                        albumTracks.Clear();
                    }
                    pos = track.position.Substring(track.position.IndexOf("-", StringComparison.Ordinal) + 1);
                }
                else if (!track.position.Substring(0, 1).All(Char.IsDigit))
                {
                    // The Master Release returned was a Vinyl Album with side A and B. So we have tracks as "A1", "A2", ... "B1",..
                    pos = track.position.Substring(1);
                    if (track.position.Substring(0, 1) == "A")
                    {
                        lastPosOnAlbumSideA = Convert.ToInt16(pos);
                    }
                    else
                    {
                        pos = (lastPosOnAlbumSideA + Convert.ToInt16(pos)).ToString();
                    }
                }
                albumTrack.Number   = Convert.ToInt16(pos);
                albumTrack.Title    = track.title;
                albumTrack.Duration = track.duration.ToString();
                albumTracks.Add(albumTrack);
            }
            discs.Add(albumTracks);
            album.Discs = discs;

            log.Trace("Discogs: Finished receiving Release");
            return(album);
        }
예제 #8
0
        private async Task <Album> GetAlbumQuery(string artistName, string albumName)
        {
            log.Debug($"MusicBrainz: Querying {artistName} - {albumName}");
            // If we have an artist in form "LastName, FirstName" change it to "FirstName LastName" to have both results
            var artistNameOriginal = _switchedArtist.IsMatch(artistName) ? $" OR {SwitchArtist(artistName)}" : "";

            var query = new QueryParameters <Release>
            {
                { "artist", $"{artistName} {artistNameOriginal}" }, { "release", albumName }
            };
            var albums = await Release.SearchAsync(query);

            // First look for Albums from the selected countries
            Release mbAlbum = null;

            foreach (var country in _options.MainSettings.PreferredMusicBrainzCountries)
            {
                mbAlbum = albums.Items.FirstOrDefault(r => r.Country == country);
                if (mbAlbum != null)
                {
                    break;
                }
            }

            if (mbAlbum == null && albums.Items.Count > 0)
            {
                mbAlbum = albums.Items[0];
            }
            else
            {
                return(null);
            }

            var release = await Release.GetAsync(mbAlbum.Id, new[] { "recordings", "media", "artists", "discids" });

            var album = new Album()
            {
                Site = "MusicBrainz"
            };

            album.LargeImageUrl = release.CoverArtArchive != null && release.CoverArtArchive.Front
        ? string.Format(@"http://coverartarchive.org/release/{0}/front.jpg", release.Id)
        : "";
            album.CoverHeight = "0";
            album.CoverWidth  = "0";
            album.Artist      = JoinArtists(release.Credits);
            album.Title       = release.Title;
            album.Year        = release.Date;
            album.DiscCount   = release.Media.Count;

            // Get the Tracks
            var discs = new List <List <AlbumSong> >();

            foreach (var medium in release.Media)
            {
                var albumTracks = new List <AlbumSong>();
                foreach (var track in medium.Tracks)
                {
                    var albumtrack = new AlbumSong();
                    albumtrack.Number = track.Position;
                    TimeSpan duration = TimeSpan.FromMilliseconds((double)track.Recording.Length);
                    albumtrack.Duration = $"{duration:mm\\:ss}";
                    albumtrack.Title    = track.Recording.Title;
                    albumTracks.Add(albumtrack);
                }
                discs.Add(albumTracks);
            }
            album.Discs = discs;
            log.Debug("MusicBrainz: Finished MusicBrainz Query");
            return(album);
        }
예제 #9
0
 public void Update(AlbumSong newAlbumSong)
 {
     throw new NotImplementedException();
 }
        public static void SeedData(IUnitOfWork unitOfWork)
        {
            //Test User
            User testUser = new User()
            {
                Id       = 1,
                Username = "******"
            };

            //Test albums
            Album album1 = new Album()
            {
                Id            = 1,
                Name          = "Album1",
                Artist        = "Artist1",
                Score         = 1,
                AlbumCoverUrl = "https://www.attackmagazine.com/wp-content/uploads/2014/11/artworks-000097027932-szvmrm-t500x500-500x479.jpg",
                Genre         = "Genre1",
                ReleaseDate   = DateTime.Now,
                Description   = "Description1"
            };

            Album album2 = new Album()
            {
                Id            = 2,
                Name          = "Album2",
                Artist        = "Artist2",
                Score         = 2,
                AlbumCoverUrl = "https://miro.medium.com/focal/1200/1200/50/40/1*8FkvzbSdSJ4HNxtuZo5kLg.jpeg",
                Genre         = "Genre2",
                ReleaseDate   = DateTime.Now,
                Description   = "Description2"
            };

            Album album3 = new Album()
            {
                Id            = 3,
                Name          = "Album3",
                Artist        = "Artist3",
                Score         = 3,
                AlbumCoverUrl = "https://cms-assets.tutsplus.com/uploads/users/114/posts/34296/image/Final-image.jpg",
                Genre         = "Genre3",
                ReleaseDate   = DateTime.Now,
                Description   = "Description3"
            };

            //Test Songs
            Song album1_song1 = new Song()
            {
                Id         = 1,
                Name       = "A1Song1",
                Artist     = "Artist1",
                Duration   = 100,
                Popularity = 1,
                Price      = 0.99
            };

            Song album1_song2 = new Song()
            {
                Id         = 2,
                Name       = "A1Song2",
                Artist     = "Artist1",
                Duration   = 10,
                Popularity = 2,
                Price      = 0.99
            };

            Song album1_song3 = new Song()
            {
                Id         = 3,
                Name       = "A1Song3",
                Artist     = "Artist1",
                Duration   = 1,
                Popularity = 3,
                Price      = 0.99
            };

            Song album2_song1 = new Song()
            {
                Id         = 4,
                Name       = "A2Song1",
                Artist     = "Artist2",
                Duration   = 200,
                Popularity = 1,
                Price      = 0.99
            };

            Song album2_song2 = new Song()
            {
                Id         = 5,
                Name       = "A2Song2",
                Artist     = "Artist2",
                Duration   = 20,
                Popularity = 2,
                Price      = 0.99
            };

            Song album3_song1 = new Song()
            {
                Id         = 6,
                Name       = "A3Song1",
                Artist     = "Artist3",
                Duration   = 3000,
                Popularity = 1,
                Price      = 0.99
            };

            Song album3_song2 = new Song()
            {
                Id         = 7,
                Name       = "A3Song2",
                Artist     = "Artist3",
                Duration   = 300,
                Popularity = 2,
                Price      = 0.99
            };

            Song album3_song3 = new Song()
            {
                Id         = 8,
                Name       = "A3Song3",
                Artist     = "Artist3",
                Duration   = 30,
                Popularity = 3,
                Price      = 0.99
            };

            Song album3_song4 = new Song()
            {
                Id         = 9,
                Name       = "A3Song4",
                Artist     = "Artist3",
                Duration   = 3,
                Popularity = 4,
                Price      = 0.99
            };

            //Album Songs
            AlbumSong album1song1 = new AlbumSong()
            {
                Album   = album1,
                AlbumId = 1,
                Song    = album1_song1,
                SongId  = 1
            };

            AlbumSong album1song2 = new AlbumSong()
            {
                Album   = album1,
                AlbumId = 1,
                Song    = album1_song2,
                SongId  = 2
            };

            AlbumSong album1song3 = new AlbumSong()
            {
                Album   = album1,
                AlbumId = 1,
                Song    = album1_song3,
                SongId  = 3
            };

            AlbumSong album2song1 = new AlbumSong()
            {
                Album   = album2,
                AlbumId = 2,
                Song    = album2_song1,
                SongId  = 4
            };

            AlbumSong album2song2 = new AlbumSong()
            {
                Album   = album2,
                AlbumId = 2,
                Song    = album2_song2,
                SongId  = 5
            };

            AlbumSong album3song1 = new AlbumSong()
            {
                Album   = album3,
                AlbumId = 3,
                Song    = album3_song1,
                SongId  = 6
            };

            AlbumSong album3song2 = new AlbumSong()
            {
                Album   = album3,
                AlbumId = 3,
                Song    = album3_song2,
                SongId  = 7
            };

            AlbumSong album3song3 = new AlbumSong()
            {
                Album   = album3,
                AlbumId = 3,
                Song    = album3_song3,
                SongId  = 8
            };

            AlbumSong album3song4 = new AlbumSong()
            {
                Album   = album3,
                AlbumId = 3,
                Song    = album3_song4,
                SongId  = 9
            };

            //Add Data
            unitOfWork.UserRepository.Create(testUser);

            unitOfWork.AlbumRepository.Create(album1);
            unitOfWork.AlbumRepository.Create(album2);
            unitOfWork.AlbumRepository.Create(album3);

            unitOfWork.SongRepository.Create(album1_song1);
            unitOfWork.SongRepository.Create(album1_song2);
            unitOfWork.SongRepository.Create(album1_song3);
            unitOfWork.SongRepository.Create(album2_song1);
            unitOfWork.SongRepository.Create(album2_song2);
            unitOfWork.SongRepository.Create(album3_song1);
            unitOfWork.SongRepository.Create(album3_song2);
            unitOfWork.SongRepository.Create(album3_song3);
            unitOfWork.SongRepository.Create(album3_song4);

            unitOfWork.AlbumSongRepository.Create(album1song1);
            unitOfWork.AlbumSongRepository.Create(album1song2);
            unitOfWork.AlbumSongRepository.Create(album1song3);
            unitOfWork.AlbumSongRepository.Create(album2song1);
            unitOfWork.AlbumSongRepository.Create(album2song2);
            unitOfWork.AlbumSongRepository.Create(album3song1);
            unitOfWork.AlbumSongRepository.Create(album3song2);
            unitOfWork.AlbumSongRepository.Create(album3song3);
            unitOfWork.AlbumSongRepository.Create(album3song4);

            unitOfWork.Commit();
        }